- 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 07:02 AM
Hi
I have modified the script like below, but it is not working. Could you please suggest where to change?
function onChange(control, oldValue, newValue, isLoading) {
var self = g_form.getValue('self');
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);
if (newValue != '' && self == 'true') {
g_form.setValue('attendees_information', details);
}
else if (newValue == '' && self == 'false'){
var toRemove = g_form.getDisplayBox('u_requested_for').value;
var finalArr = [];
var parser = JSON.parse(details);
for(var i=0;i<parser.length;i++){
var obj1 = parser[i];
var newParser = JSON.parse(JSON.stringify(obj1));
if(newParser.attendee_name != toRemove){
finalArr.push(obj1);
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-15-2021 07:17 AM
Hi,
can you try to update as this
function onChange(control, oldValue, newValue, isLoading) {
var self = g_form.getValue('self').toString();
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);
if (newValue != '' && self == 'true') {
g_form.setValue('attendees_information', details);
}
else if (newValue == '' && self == 'false'){
var toRemove = g_form.getDisplayBox('u_requested_for').value;
var finalArr = [];
var parser = JSON.parse(details);
for(var i=0;i<parser.length;i++){
var obj1 = parser[i];
var newParser = JSON.parse(JSON.stringify(obj1));
if(newParser.attendee_name != toRemove){
finalArr.push(obj1);
}
}
alert('new JSON' + JSON.stringify(finalArr));
g_form.setValue('attendees_information',JSON.stringify(finalArr));
}
}
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 07:40 AM
Hi
Alert is showing "new JSON[]" and not working as expected.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-15-2021 07:49 AM
Hi,
try adding alert here
where are you running this on native or portal?
getDisplayBox -> works only in native
function onChange(control, oldValue, newValue, isLoading) {
var self = g_form.getValue('self').toString();
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);
if (newValue != '' && self == 'true') {
g_form.setValue('attendees_information', details);
}
else if (newValue == '' && self == 'false'){
var details1 = g_form.getValue(attendees_information'');
var toRemove = g_form.getDisplayBox('u_requested_for').value;
var finalArr = [];
var parser = JSON.parse(details1);
for(var i=0;i<parser.length;i++){
var obj1 = parser[i];
var newParser = JSON.parse(JSON.stringify(obj1));
if(newParser.attendee_name != toRemove){
finalArr.push(obj1);
}
}
alert('new JSON' + JSON.stringify(finalArr));
g_form.setValue('attendees_information',JSON.stringify(finalArr));
}
}
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 07:55 AM
Hi
I want it to work on both native and Portal. But right now, I am testing it in native.