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 11:21 PM
Hi Aniket,
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:08 AM
Hello @Pihu1 ,
Please try with the below modified code.
createIncident: function (caller, urgency, description, category, inc_fields) {
var incDetails = {};
var incGr = new GlideRecord("incident");
incGr.initialize();
incGr.setValue("caller_id", caller);
incGr.setValue("urgency", urgency);
incGr.setValue('category', category);
incGr.setValue("description", description);
// Check if inc_fields array has enough elements before accessing them
if (inc_fields && inc_fields.length >= 2) {
incGr.setValue("u_on_behalf_of", inc_fields[0]);
incGr.setValue("short_description", inc_fields[1]);
}
// Check if inc_fields array has enough elements before accessing the state
if (inc_fields && inc_fields.length >= 3) {
incGr.setValue("state", inc_fields[2]);
}
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