We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. 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 ?

2 REPLIES 2

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