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
Author
Message
AlexUhde View Drop Down
New User
New User


Joined: 26 Dec 2017
Location: Brisbane
Points: 14
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: 118
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: 14
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: 118
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: 14
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
 Post Reply Post Reply
  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.051 seconds.