Pass an array from a client script to a ui page and finally to a script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2018 06:42 AM
Hi all,
sorry for the potentially dumb question but I couldn't find anything useful anywhere:
I have an on change client script that launches a UI Page (glideDialogWindow) in which user has to insert some information.
The ok button of the dialog will launch a script include class that will do stuff, along with updating some values of the item from where the client script started.
I would love to also commit the edited fields (edited prior to the ui page loading) including the field that triggers the on change client script.
(I don't know if I'm clear)
I thought about passing a 2 dimensional array (couple 'fieldname' - 'fieldvalue') of the g_form.elements from the client script to the dialog, in order to then pass those again to the script include, and finally commit the changed ones.
Unfortunately I see that the glideDialogWindow.setPreference only supports string..
Is there a way to pass the array through?
If no, is there a different way to do what I need?
EDIT:
I have passed two strings like element1,element2,element3 / value1,value2,value3, splitting them afterwards. It works, but now I have another issue:
How can I call gr.fieldname starting from a list of fieldnames? (like dynamic javascript?)
Thanks a lot.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2018 09:27 AM
Hi,
Regarding passing the parameters, I would suggest you to use JSON.
Create a data structure in JSON (it can contain arrays). Then Stringify it to make it a single string.
Pass it to your target. Then parse to get the structure back to an object.
JSON is cool because you don't have to worry about special characters (like " or ,) that can break your code.
Client-side JSON example :
var a = {'login':'xyz'};
b = JSON.stringify(a);
var c = JSON.parse(b);
c.login; //xyz
Regarding your second point:
> How can I call gr.fieldname starting from a list of fieldnames? (like dynamic javascript?)
I think you're looking for the gr[field] style notation:
var gr = new GlideRecord('incident');
gr.get('5058cbd6dc4b178018d45500f880dbd5');
myfield = 'number';
gs.print(gr[myfield]);
Note: dot-walking is still the best practice notation, this one should only be used when you can't do otherwise
Regards,
Marc