Incident caller autopopulate

shivaadapa
Tera Expert

Hi

shivaadapa_0-1712903052177.png

Here I want to populate caller field in the owner field(referring to user field same as like caller field) what ever the incident number populating  that caller should be populated in the owner field.
I tried reference qualifier in the owner field - 

shivaadapa_1-1712903603197.png

 

3 REPLIES 3

Shubham26
Tera Guru

Hi @shivaadapa 

 

Reference qual, only used to filter data from reference table, and provides data to select in reference field as per reference qual.

 

If you  want to autopopulate Owner field, you  have to write the onchange client script on Incident field, and call glide ajax function to get incident caller value from server end and then set the value in u_owner field with sys id of the user which you will receive from server through glide ajax function.

 

 

I hope, you know the way to use Glide Ajax. if not please visit below URLs:

 

https://developer.servicenow.com/dev.do#!/reference/api/utah/client/c_GlideAjaxAPI

 

https://docs.servicenow.com/bundle/washingtondc-api-reference/page/app-store/dev_portal/API_referenc...

 

Let me know if you need any more help with this.

Please mark my answer helpful and correct.

 

Thank You.

 

Regards,

Shubham Gupta

Astik Thombare
Tera Sage

Hi @shivaadapa ,

 

You can also achieve this using a Calculated Value. To configure it, right-click on the owner field, select "Configure Dictionary," then go to "Advanced View." Under "Calculated Value Related List," check the "Calculated" box and enter the script in the designated area as per below .

 

AstikThombare4_0-1712904719565.png

 

 

AstikThombare4_1-1712904769184.png

 

AstikThombare4_2-1712904871514.png

 

 

(function calculatedFieldValue(current) {

if(!current.caller_id.nil())
	return current.caller_id;  // return the calculated value

})(current);

 

 

 

Final Outcome -

 

AstikThombare4_3-1712904975569.png

 

In addition to calculated values, you can also use other methods like GlideAjax or the getReference method to auto-populate the Owner field.

 

GlideAjax -

https://www.servicenow.com/community/developer-forum/populate-field-value-based-on-another-field-usi... 

 

getReference -

https://www.servicenow.com/community/itsm-forum/a-way-to-auto-populate-fields-based-on-another-field...

 

if my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.

 

Thanks,

Astik

 

Rohit99
Mega Sage

Hi @shivaadapa,

 

You can also achieve this using Client Script and Script Include.

 

Client Script as per below:

Type: on change

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var ga = new GlideAjax('Incident_Script');
   ga.addParam('sysparm_name','fetching_Caller');
   ga.addParam('sysparm_value',g_form.getValue('u_incident_number'));
   ga.getXML(getResult);

   function getResult(response)
   {
    var answer = response.responseXML.documentElement.getAttribute('answer');
    g_form.setValue('u_owner',answer);
   }
}
 
screenshot_04.PNG

 
Script Include as per below:
 
var Incident_Script = Class.create();
Incident_Script.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    fetching_Caller : function(test)
    {
        var incnum = this.getParameter('sysparm_value');
        var gr = new GlideRecord('incident');
        gr.addQuery('sys_id',incnum);
        gr.query();
        if(gr.next())
        {
            return gr.caller_id;
        }

    },
    type: 'Incident_Script'
});
 
screenshot_05.PNG

 

Please mark my response as correct and helpful if it helped solved your question.