Using Script field types

iaind
Kilo Contributor

What are the options for executing code stored in custom tables using the Script field type?

I'll give a simple scenario:

I have a large (mostly static) JSON payload to submit to Slack.   The dynamic data is updated using "macros".   Each macro is a simple bit of JavaScript to collect the data from somewhere else:

for example: The Macro is called Color and presented in JSON as "${Color}"

answer = (function(myTask, inAction) {

              var sColor = '#ff0000';

              var nPriority = myTask.priority + '';

              var sTemp = gs.getProperty('ppb.integration.slack.macro.Colors', '5:#66ff66,4:#3366ff,3:#ff6600,2:#ff33cc,1:#ff0000');

              var aTemp = sTemp.split(',');

              for ( var i = 0; i <= aTemp.length; i++ ) { var aRow = aTemp[i].split(':'); if ( aRow[0] + '' == nPriority ) { sColor = aRow[1] + ''; break; } }

              return sColor;

})(myTask, inAction);

This is used to replace a "macro" in the JSON which would look something like this:

{"username":"${SlackUsername}","attachments":[{"title":"Short description","title_link":"${URL}","text":"${ShortDescription}","color":"${Color}"],"ts":"${TimeStampEpoch}"}]}

The question I have now is, what options are there to run the script in the Script field without using something like this:

gs.print('[' + answer + ']');

var F = new Function(glider.u_macro_script);

F();

gs.print('[' + answer + ']');

There's a separate process for matching the macro values in the end...

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Iain,



You might find this useful. See the attached lab guide and use the URL below for the repository.



It was a self-paced lab I built for CreatorCon 16 to introduce you to using Script fields. It requires you have a GitHub account. Fork the repository, then go in to Studio and import the repository. The only major difference between the attached lab guide and now is that we won't be providing an instance for you.



GitHub - chucktomasi/CC-HackLab-ScriptField: CreatorCon Hack Lab to learn how to use the script fiel...


View solution in original post

5 REPLIES 5

Chuck Tomasi
Tera Patron

Hi Iain,



You might find this useful. See the attached lab guide and use the URL below for the repository.



It was a self-paced lab I built for CreatorCon 16 to introduce you to using Script fields. It requires you have a GitHub account. Fork the repository, then go in to Studio and import the repository. The only major difference between the attached lab guide and now is that we won't be providing an instance for you.



GitHub - chucktomasi/CC-HackLab-ScriptField: CreatorCon Hack Lab to learn how to use the script fiel...


If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thank you


Hi Chuck,

 

I see I am a few years late to the party...  Thank you for providing the links above.  Just this morning, I was trying to complete this lab.  The GitHub repository forked as expected, and I was able to import the application to my dev instance.  While building the UI action, I cannot find the Sample Scripts referenced in the attached document: "Lab1 - UI Action" (page7), "Lab2 - UI Action" and "Lab2 - Beth" (both on page 11) and "Lab3 - Fred" and "Lab3  UI Action" (page 14).  I tried looking thru the XML files on the GitHub repository, and did not find anything.  Would you happen to know of anywhere I might be able to find these old scripts?

After loading the app from GitHub, did you refresh your main browser page? The scripts are in the records found under Lego> Scripts.