diff --git a/Client Scripts/Set Severity, state & assigned to/Readme.md b/Client Scripts/Set Severity, state & assigned to/Readme.md new file mode 100644 index 0000000000..bb4ca201cf --- /dev/null +++ b/Client Scripts/Set Severity, state & assigned to/Readme.md @@ -0,0 +1,11 @@ +Use the script provided in script_include.js and script.js to set fetch multiple values from server to client side by passing an +object from server to the client side and setting values on your form. This can be used to pass multiple parameters from server to +client side. + +Use Case: +Consider you have a reference field on your form referring to "sn_si_incident" and you need to set Severity, state and assigned to +onChange of the reference field. + +Solution: +Create a client callable script include as mentioned in script_include.js and pass the required values to your client script. +Then use the onChange client script in script.js to set values on the form. diff --git a/Client Scripts/Set Severity, state & assigned to/script.js b/Client Scripts/Set Severity, state & assigned to/script.js new file mode 100644 index 0000000000..c0fb9f5842 --- /dev/null +++ b/Client Scripts/Set Severity, state & assigned to/script.js @@ -0,0 +1,25 @@ +//onChange client script + +function onChange(control, oldValue, newValue, isLoading, isTemplate) { + if (isLoading || newValue === '') { + + return; + } + + + //Type appropriate comment here, and begin script below + var ga = new GlideAjax('getSIRDetails'); // calling script include + ga.addParam('sysparm_name', 'getDetails'); + ga.addParam('sysparm_sir', newValue); //passing newValue to the script include + ga.getXMLAnswer(callBackFunction); + + + function callBackFunction(response) { + var ans = JSON.parse(response); + g_form.setValue('severity', ans.severity); // setting values from the obj to appropriate fields + g_form.setValue('soc_sir_state', ans.state); + g_form.setValue('soc_sir_assigned_to', ans.assignedto); + + + } +} diff --git a/Client Scripts/Set Severity, state & assigned to/script_include.js b/Client Scripts/Set Severity, state & assigned to/script_include.js new file mode 100644 index 0000000000..93737dccfd --- /dev/null +++ b/Client Scripts/Set Severity, state & assigned to/script_include.js @@ -0,0 +1,18 @@ +//Client callable script include +var getSIRDetails = Class.create(); +getSIRDetails.prototype = Object.extendsObject(global.AbstractAjaxProcessor, { + getDetails: function() { + var sir = this.getParameter('sysparm_sir'); //getting the newValue of Security Inc from onChange client script + var obj = {}; //declare an object + var gr = new GlideRecord('sn_si_incident'); + gr.addQuery('sys_id', sir); //Query to security incident table with the newValue + gr.query(); + if (gr.next()) { + obj.severity = gr.severity.getDisplayValue(); //Setting values in the obj + obj.state = gr.state.getDisplayValue(); + obj.assignedto = gr.assigned_to.getDisplayValue(); + } + return JSON.stringify(obj); //passing the object to client script + }, + type: 'getSIRDetails' +});