- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-15-2021 02:54 AM
Hi All,
Hope everyone is doing good.
I am working on a catalog form with Variables,
Name (reference to User table), Department, Work Location, Telephone, Email. When value changes in Name variable, all the other variables get populated automatically if the user in Name variable has that values exist. If not, we are allowing users to manually enter values in Department, work location, telephone, email variables.
We have a MRVS with the same variables as mentioned above.
Now, We have a checkbox variable on the same form with name "Self". When user checks it to true, all the values in the Name, Department, work location, telephone, email should be copied to variables in MRVS. If he unchecks, the values should get cleared (only the row should get deleted which is populated when the variable is checked). This should work on change of both Name and Self variables.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-21-2021 06:17 AM
Done and working fine in native
please check below output
Please mark my response as correct and close the question.
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-15-2021 04:05 AM
Hi,
in the 2nd link I have shared the approach
form array of JSON objects and return that using onChange + GlideAjax
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-15-2021 04:18 AM
Hi
I am thinking like, Instead of using script include, to get the user details in Name variable, we can directly get the existing values in the variables on the catalog form and pushing them into each relatable variable in MRVS. So using glide Ajax is not required right?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-15-2021 04:24 AM
Hi,
correct. no ajax required
1) get the JSON array
2) iterate one by one and match
3) then push the value in new array
4) then set the values in MRVS i.e. the final JSON
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-15-2021 06:07 AM
Hi
I have written the following lines of code and it is populating the details onLoad. But if I change the value of self, it is not working. Could you also please help on deleting specific row that was populated with this value change?
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
g_form.clearValue('attendees_information');
}
var selfDetails = [];
var details = '';
var obj = {};
obj["attendee_name"] = g_form.getDisplayBox('u_requested_for').value;
obj["email_address"] = g_form.getValue('u_email');
obj["department"] = g_form.getValue('u_department');
obj["u_work_location"] = g_form.getValue('work_location');
obj["telephone_number"] = g_form.getValue('u_telephone');
selfDetails.push(obj);
details = JSON.stringify(selfDetails);
// var self = g_form.getValue('self');
// if (self == true) {
g_form.setValue('attendees_information', details);
// } else {
// g_form.clearValue('attendees_information', details);
// }
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-15-2021 06:36 AM
Hi,
here is sample script on how to remove json object from array of json objects
var json = '[{"name":"Abel","email":"abel@example.com"},{"name":"Beth","email":"beth@example.com"}]';
var toRemove = 'Abel';
var finalArr = [];
var parser = JSON.parse(json);
for(var i=0;i<parser.length;i++){
var obj = parser[i];
var newParser = JSON.parse(JSON.stringify(obj));
if(newParser.name != toRemove){
finalArr.push(obj);
}
}
gs.info(JSON.stringify(finalArr));
Output:
[0:00:00.063] Script completed in scope global: script
Script execution history and recovery available here
*** Script: [{"name":"Beth","email":"beth@example.com"}]
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader