Auto- Populate service level field based on selection of affected CI on Incident table

deepikagang
Tera Contributor

Hi All,

Want to populate custom field (u_service_level) based on selection of affected ci reference to cmdb_ci table.

 

deepikagang_0-1739783778431.png

 

Thank you in advance

 

Best regards

Deepika

15 REPLIES 15

Ahmmed Ali
Mega Sage

Hello @deepikagang 

 

Are you storing the Service Level value in CMDB CI record? if yes, then you can create onchange client script on the change of affected CI, then call a script include through GlideAjax, query the CI record and get the service level value and return the same to client. In client script you can populate the answer from Service to the Service Level field.

 

Below threads shows example scripts for assignment group, you can have similar script for your service level field.

 

https://www.servicenow.com/community/developer-forum/auto-populate-assignment-group/m-p/2343293

 

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Thank you @Ahmmed Ali for your reply.
I tried but no luck. Can you please help me with the correct code.
Note: service level field is custom field on cmdb_ci_service table and we made visible on incident form.

 

Below are my script include and client script:

var setServiceLevel = Class.create();
setServiceLevel.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateservicelevel : function(){
var gr=new GlideRecord('cmdb_ci');
gr.addQuery('name',this.getParameter('sysparm_cmdb_ci'));
    gr.query();
if(gr.next())
{
return gr.u_service_level;
}

},
    type: 'setServiceLevel'
});
 
Client script :
    if (isLoading || newValue == '') {
        return;
    }
var ga = new GlideAjax('setServiceLevel'); //script include name
    ga.addParam('sysparm_name', 'populateservicelevel'); //script include function name
    ga.addParam('sysparm_cmdb_ci', g_form.getValue('cmdb_ci')); //parameter passeed
    ga.getXML(getResponse);

    function getResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('u_support_service.u_service_level', answer);
    }
}

@deepikagang 

the field in your screenshot is dot walked from Support Service.

Why are you setting it via script?

That's not the correct way to set.

Ideally it will auto populate based on Support service selected on form

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello @deepikagang 

 

First issue is you have dot walked field on the incident table. Ideally if you want to show the field from affected CI record, you can simply add dot walked "Service Level" field from the affected CI field, which should show backend name as cmdb_ci.u_service_level. Now when new CI is selected, your service level will auto-populate.

BUT

If you want to have the Service Level field created in incident (which should be good to keep historical data. means the support level of CI can be changed any time and for past incidents as well it will show new value if dot walked which will be wrong as per my understanding).

Now, create new field in incident table called Support Level. In above script include change return gr.u_service_level; to return gr.u_service_level.toString(); and update your custom field in client script set value statement.

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali