Assigning sys_id display value to string field in servicenow

20 views Asked by At

I'm trying to create a button on feedback form named create incident. once user click on button then indent should be created and the the number of the created incident should be populated in string field on feedback form (on existing record).

here code snippet

1

There are 1 answers

0
Maciej Zapart On

I think client UI Action & client callable script include is what you need to fulfil requirements.

I have form which like on this pic:enter image description here

In example I created for you: ui action configuration

this is script include which returns server side info

this is ui action script:

function onClick() {
    var ga = new GlideAjax('getIncidentInfo'); // getIncidentInfo is the script include name 
    ga.addParam('sysparm_name', 'createNewIncident'); // createNewIncident is the function in the script include that we're calling 
    ga.addParam('sysparm_assigned_to', g_form.getValue('assigned_to')); // set field as example
    /* Call getIncidentInfo.createNewIncident() with "assigned to" set to g_form.assigned_to  and use the callback function ManagerParse() to return the result when ready */
    ga.getXMLAnswer(populateIncident);

}
// callback function for returning the result from the script include
function populateIncident(response) {
    g_form.setValue('u_related_incident', response)
    g_form.save();
}

this is script include:

var getIncidentInfo = Class.create();
getIncidentInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    createNewIncident: function() {
        var gr = new GlideRecord('incident');
        gr.initialize();
        gr.setValue('assigned_to', this.getParameter("sysparm_assigned_to"));
        gr.insert();
        var uid = gr.getUniqueValue()
        var result = uid;
        return result;
    },
    type: 'getIncidentInfo'
});

To learn more about GlideAjax usage see this tutorial:

https://developer.servicenow.com/dev.do#!/learn/learning-plans/washingtondc/servicenow_application_developer/app_store_learnv2_scripting_washingtondc_extending_glideajax

for more information take a look here: https://developer.servicenow.com/dev.do#!/reference/api/vancouver/client/c_GlideAjaxAPI