Parker Software Ltd Homepage
Forum Home Forum Home > ThinkAutomation Business Process Automation > Scripting
  New Posts New Posts RSS Feed - Converting Units from an extracted field
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Converting Units from an extracted field

 Post Reply Post Reply Page  12>
Author
Message
AlexUhde View Drop Down
New User
New User


Joined: 26 Dec 2017
Location: Brisbane
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote AlexUhde Quote  Post ReplyReply Direct Link To This Post Topic: Converting Units from an extracted field
    Posted: 17 May 2018 at 12:15am
Hello,

I'm trying to convert bytes to GB from an status email.

So I have my extracted field "Data_Used", which is just the digits from the email in bytes.
I then have a variable (Data_used_GB) which I set via a script.
This doesn't seem to work.
I have to say that I have never done some ThinkAutomate scripting before.

My script:
Sub Main()
    ' commands start here
    Dim DataUsed As Integer
    DataUsed = CInt(ThinkAutomationMessage.ExtractedFields("Data_Used").Value)
    AccountVariable("Data_used_GB") = DataUsed / 1073741824

End Sub

Can someone please point me in the right direction?

Kind regards,
Alex
Back to Top
parkersoft-jim View Drop Down
Admin Group
Admin Group
Avatar

Joined: 11 Nov 2016
Location: Terra
Points: 121
Post Options Post Options   Thanks (0) Thanks(0)   Quote parkersoft-jim Quote  Post ReplyReply Direct Link To This Post Posted: 17 May 2018 at 3:08am
Are you trying to convert Bytes to Gigabyte, using a value you've obtained from a message that was processed?
Back to Top
AlexUhde View Drop Down
New User
New User


Joined: 26 Dec 2017
Location: Brisbane
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote AlexUhde Quote  Post ReplyReply Direct Link To This Post Posted: 17 May 2018 at 3:13am
Hello Jim,

Yes, I extracted just the numbers from that message and saved them in %Data_Used%
I want to convert it to GB (just the numbers) and save it as %Data_used_GB% and then use that down the line in the Triggers.

Kind regards,
Alex
Back to Top
parkersoft-jim View Drop Down
Admin Group
Admin Group
Avatar

Joined: 11 Nov 2016
Location: Terra
Points: 121
Post Options Post Options   Thanks (0) Thanks(0)   Quote parkersoft-jim Quote  Post ReplyReply Direct Link To This Post Posted: 17 May 2018 at 6:49am
Assuming you have the MegaByte value in your Extracted Field variable %Data_Used% and its a whole number, not a decimal you could use the below method.

First create a Set Variable trigger action, I call mine Gig, and this can then be used as %Gig% in your later trigger actions.

Then create a Run a ThinkAutomation Script trigger action and ensure it is after the first Set Variable.

Set the contents below.


Sub Main()
    Dim G As Long
    G = CLng(AccountVariable("Data_Used"))
    G = G / 1024
    AddToLog("Calculation = " & G)
    AccountVariable("Gig") = G
End Sub

The below is a duplicate of the above but just with comments on what each line is doing. Don't put both in your script.

Sub Main()
' create a variable called G
    Dim G As Long
' Set G to the contents of your extracted field variable and make it a long number
    G = CLng(AccountVariable("Data_Used"))
' perform calulation here to divide by 1024
    G = G / 1024
'Adding output value to trigger process log
    AddToLog("Calculation = " & G)
'Sets the Gig variable in an earlier trigger action to the outputted value
    AccountVariable("Gig") = G
End Sub
Back to Top
AlexUhde View Drop Down
New User
New User


Joined: 26 Dec 2017
Location: Brisbane
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote AlexUhde Quote  Post ReplyReply Direct Link To This Post Posted: 21 May 2018 at 6:59pm
Hello Jim,

Thank you very much.
I'm testing this now and will let you know if it works.
It's not a Trigger which happens often.

Kind regards,
Alex
Back to Top
AlexUhde View Drop Down
New User
New User


Joined: 26 Dec 2017
Location: Brisbane
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote AlexUhde Quote  Post ReplyReply Direct Link To This Post Posted: 11 Jun 2018 at 6:42pm
Hello Jim,
Sorry for the late reply, I just had some time trouble shooting (and I found the "Run with" option)...

The script not returning any value for me.
Just a bit more detail:
The email:
Bill: Company
Monitored port: Outside
Usage: 100458233713 used of 100000000000 bytes

phgbnerou has used 100% of its monthly quota at 2018-06-08 10:01:24

Additional usage may be chargeable!

The next warning will be issued at 125% 
Note data may be delayed by up to 1 hour.

from there I extract the Company, Data_Used, Data_Total and msg_rest.
Data_Used and Total are just the digits.


Then I try to use "Set Variable" to set Data_Used_GB and Data_Total_GB via the script you gave me.
Unfortunately I only get a blank result.
The Log just shows "Data used in GB = 0"



Kind regards,
Alex

Back to Top
parkersoft-jim View Drop Down
Admin Group
Admin Group
Avatar

Joined: 11 Nov 2016
Location: Terra
Points: 121
Post Options Post Options   Thanks (0) Thanks(0)   Quote parkersoft-jim Quote  Post ReplyReply Direct Link To This Post Posted: 12 Jun 2018 at 9:17am
I've tried my own script again and for some reason I get '0'.

Try the below instead;

Sub Main()
' commands start here
Dim iG As Long
iG = CLng(FIELDS_Value("Data_Used"))
iG = iG / 1024
AddToLog("Calculation = " & iG)
AccountVariable("Gig") = iG
End Sub




Edited by parkersoft-jim - 12 Jun 2018 at 9:34am
Back to Top
AlexUhde View Drop Down
New User
New User


Joined: 26 Dec 2017
Location: Brisbane
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote AlexUhde Quote  Post ReplyReply Direct Link To This Post Posted: 19 Jun 2018 at 1:34am
Hello Jim,

0 was the result I was getting as well.
changing it to "FIELDS_Value" gives me a Type mismatch.

Back to Top
parkersoft-jim View Drop Down
Admin Group
Admin Group
Avatar

Joined: 11 Nov 2016
Location: Terra
Points: 121
Post Options Post Options   Thanks (0) Thanks(0)   Quote parkersoft-jim Quote  Post ReplyReply Direct Link To This Post Posted: 19 Jun 2018 at 5:16am
"Data_Used" is referring to the variable you are extracting from, that may have been renamed.

If not, all I can add is that my script was written in ThinkAutomation 4.2.1646.
Back to Top
AlexUhde View Drop Down
New User
New User


Joined: 26 Dec 2017
Location: Brisbane
Points: 18
Post Options Post Options   Thanks (0) Thanks(0)   Quote AlexUhde Quote  Post ReplyReply Direct Link To This Post Posted: 21 Jun 2018 at 12:00am
Hello Jim,

"Data_Used" is the name of the extracted field.
I also tried to set this into a variable and use that in the Script, no luck.

I'm running the same version (4.2.1646).

UPDATE: I got pointed out, that an INT can't store the number size I'm working with (100000000000). So I'm going to test it with a Single now.


Edited by AlexUhde - 21 Jun 2018 at 12:22am
Back to Top
 Post Reply Post Reply Page  12>
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.05
Copyright ©2001-2016 Web Wiz Ltd.

This page was generated in 0.062 seconds.