- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 09:08 PM
Hi All,
I have written an OnChange client script and client-callable script includes in order to set value of Vendor field in Incident task table according to value of assignment group:
Here is the client script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 09:23 PM
@Community Alums Please update your client script and script include as follows.
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.addInfoMessage("New Value is" + newValue);
var ga = new GlideAjax('Set_Vendor_to_sync_with_asssignment_group');
ga.addParam('sysparm_name', 'fetchVendor');
ga.addParam('sysparm_assignment_group',newValue); //Always use sysparm_ prefix before the parameter names
ga.getXML(generateResponse);
function generateResponse(response) {
var vendor = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage("Response is"+vendor);
g_form.setValue('u_vendor', vendor);
}
//Type appropriate comment here, and begin script below
}
Script Include:
var Set_Vendor_to_sync_with_asssignment_group = Class.create();
Set_Vendor_to_sync_with_asssignment_group.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fetchVendor: function(assignment_group) {
var assignmentGroup = this.getParameter("sysparm_assignment_group")?this.getParameter("sysparm_assignment_group"):assignment_group;
gs.info("fetchVendor function called" +assignmentGroup);
var mapping = gs.getProperty('vendor.group.mapping');
var mappingObj = JSON.parse(mapping);
var vendor = mappingObj[assignmentGroup];
gs.info("vendor according to group is"+vendor);
return vendor;
},
type: 'Set_Vendor_to_sync_with_asssignment_group'
});
There is a slight difference in fetching the parameter passed from the client side. As you need to use this.getParameter to get the parameter value.
The changes made in the script include script will allow you to fetch values for both server side and client side.
var assignmentGroup = this.getParameter("sysparm_assignment_group")?this.getParameter("sysparm_assignment_group"):assignment_group;
Please mark the response helpful and accepted solution if it manages to answer your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 09:23 PM
@Community Alums Please update your client script and script include as follows.
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.addInfoMessage("New Value is" + newValue);
var ga = new GlideAjax('Set_Vendor_to_sync_with_asssignment_group');
ga.addParam('sysparm_name', 'fetchVendor');
ga.addParam('sysparm_assignment_group',newValue); //Always use sysparm_ prefix before the parameter names
ga.getXML(generateResponse);
function generateResponse(response) {
var vendor = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage("Response is"+vendor);
g_form.setValue('u_vendor', vendor);
}
//Type appropriate comment here, and begin script below
}
Script Include:
var Set_Vendor_to_sync_with_asssignment_group = Class.create();
Set_Vendor_to_sync_with_asssignment_group.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fetchVendor: function(assignment_group) {
var assignmentGroup = this.getParameter("sysparm_assignment_group")?this.getParameter("sysparm_assignment_group"):assignment_group;
gs.info("fetchVendor function called" +assignmentGroup);
var mapping = gs.getProperty('vendor.group.mapping');
var mappingObj = JSON.parse(mapping);
var vendor = mappingObj[assignmentGroup];
gs.info("vendor according to group is"+vendor);
return vendor;
},
type: 'Set_Vendor_to_sync_with_asssignment_group'
});
There is a slight difference in fetching the parameter passed from the client side. As you need to use this.getParameter to get the parameter value.
The changes made in the script include script will allow you to fetch values for both server side and client side.
var assignmentGroup = this.getParameter("sysparm_assignment_group")?this.getParameter("sysparm_assignment_group"):assignment_group;
Please mark the response helpful and accepted solution if it manages to answer your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 09:48 PM
Thank you @Sandeep Rajput .