Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Regarding population of location field

rutujalande
Tera Contributor

Hello,

 

I am having requirement to auto populate location field when configuration item (CI) is selected on incident form. for both the fields data is taking from cmdb_ci table. i have written client on change script and script include but its not giving results. Any suggestions on this ?

3 REPLIES 3

Tanushree Maiti
Tera Patron

Hi @rutujalande 

 

Try this:

  1. The Script Include
  • Name: CIUtils
  • Client callable: Checked

 

var CIUtils = Class.create();

CIUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getCILocation: function() {

        var ciSysId = this.getParameter('sysparm_ci_id');

        var locationId = '';       

        if (ciSysId) {

            var grCI = new GlideRecord('cmdb_ci');

            if (grCI.get(ciSysId)) {

                       locationId = grCI.getValue('location') || '';

            }

        }

        return locationId;

    },

    type: 'CIUtils'

});

 

  1. Create onChange Client Script
  • Name: Populate Location from CI
  • Table: Incident
  • Field name: Configuration item [cmdb_ci]
  • Type: onChange

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '') {

        if (newValue === '') {

            g_form.clearValue('location');

        }

        return;

    }

    var ga = new GlideAjax('CIUtils');

    ga.addParam('sysparm_name', 'getCILocation');

    ga.addParam('sysparm_ci_id', newValue);

        if (response) {

            g_form.setValue('location', response); // Sets the actual location reference field

        } else {

            g_form.clearValue('location');

        }

    });

}

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Ankur Bawiskar
Tera Patron

@rutujalande 

so what debugging did you do?

script include is client callable?

both script include and client scripts are in same scope?

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

Ehab Pilloor
Mega Sage

Hi @rutujalande,

 

Try setting default value from dictionary as javascript: current.cmdb_ci.location;

 

Expect it to populate on save or update.

 

Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.

 

Kind Regards,

Ehab Pilloor