Need help in setting values from array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 10:43 PM
Hi Community,
I need help in setting field values from an array containing strings. I have a requirement to set incident fields short description, on behalf of and state from an array containing string values.
For example, I am passing an array to Script include function as a parameter as below where inc_fields is an array containing values ["7110868edb5325907e04450b1396199b","test created inc","2"]
How to set fields from this array? below is my code

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 10:55 PM
just pass the array as the functional parameter, assuming the sequence is correct
createIncident: function (arr) {
var incDetails = {};
var incGr = new GlideRecord("incident");
incGr.initialize();
incGr.setValue("caller_id", arr[0]);
incGr.setValue("urgency", arr[1]);
incGr.setValue('category', arr[2]);
incGr.setValue("description", arr[3]);
incGr.setValue("u_on_behalf_of", arr[4]);
incGr.setValue("short_description", arr[5]);
incGr.setValue("state", arr[]);6
incDetails.sysid = incGr.insert();
incDetails.incNum = incGr.getValue('number');
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 11:21 PM - edited 02-14-2024 11:22 PM
Hi Aman,
I don't want to set all the fields from the array, here only inc_fields is a array which contains values and want to set short description , on behalf of and state.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 02:12 AM
so inc_fields is your array, can you share how are you populating the array, and how the values looks like. share the code as well.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 11:05 PM
Hello @Pihu1 ,
Please give a try to the modified code below and see how it works for you.
createIncident: function (arr) {
var incDetails = {};
var incGr = new GlideRecord("incident");
incGr.initialize();
incGr.setValue("caller_id", arr[0]);
incGr.setValue("urgency", arr[1]);
incGr.setValue('category', arr[2]);
incGr.setValue("description", arr[3]);
incGr.setValue("u_on_behalf_of", arr[4]);
incGr.setValue("short_description", arr[5]);
incGr.setValue("state", arr[6]); // Corrected the index
incDetails.sysid = incGr.insert();
incDetails.incNum = incGr.getValue('number');
return incDetails;
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket