I want to auto populate Issue location, CCID, Simphony ID based on the opened for

kranthi2
Tera Expert

Hi,

I want to auto populate Issue location, CCID, Simphony ID based on the opened for.

But here Issue location and Simphony ID is coming from CCID table

 

kranthi2_0-1705566040168.png

 

sys_user (user) table screenshot:

kranthi2_1-1705566270906.png

 

CCID Table has Simphony ID and Issue location:

 

kranthi2_2-1705566412670.png

 

Thanks,

Sreenadh

 

 

 

 

 

 

 

4 REPLIES 4

Jaspal Singh
Mega Patron
Mega Patron

Hi Sreenadh,

For cases like these that are more of double dot-walk I always fine Michale's article handy.

Chaitanya naram
Kilo Sage

Hi @kranthi2 You can do it in two ways


1st way:

1) Go to CCID Catalog variable, where you see Autopopulate section. Select Opened For as the dependent question and refence to CCID field.

2) Go to Issue location and Symphony ID Catalog variables, where you see Autopopulate section. Select CCID catalog variable as the dependent question and refence to Issue location and Symphony ID fields respectively.

2nd WAY:

Write an onchange client script for Opened for and set the values

 

 

Thanks & Regards | Chiranjeevi Chaitanya Naram
Kindly mark the answer Correct and Helpful if it helps to resolve your issue.

Harish KM
Kilo Patron
Kilo Patron

Hi @kranthi2 here is the example , make sure field names and variable names are correct.

Script Include:

getRequestorDetails:function()
{
var userData = {};
var userCcid= '';
var SysID = this.getParameter('sysparm_id');//opened for sysid
var user = new GlideRecord('sys_user');
user.addQuery('sys_id',SysID);
user.query();
if(user.next())
{
userCcid = user.getValue('ccid');//ccid field from user table

var cid = new GlideRecord('tableName'); // ccid table
cid.addQuery('ccid',userCcid);
cid.query();
if(cid.next())
{
userData.cid = user.getValue('u_uid');
userData.address = cid.getValue('address');
userData.id = cid.getValue('symphony_id');
}
}
var answer = JSON.stringify(userData);
return answer;

},

 

CLient Script:

client script onchange on opened For variable
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
g_form.setValue('variablename', '');// to clear value when variable changes

return;
}

var si = new GlideAjax('Script Include Name');
si.addParam('sysparm_name', 'getRequestorDetails');// scriptinclude function name
si.addParam('sysparm_sysid', newValue); // opened for value
si.getXMLAnswer(parseResponse);

function parseResponse(answer) {
var response = JSON.parse(answer);

alert(JSON.Stringify(response,nulln4)); // check response from Script include

g_form.setValue('variableName', response.cid);
g_form.setValue('variableName', response.address);
g_form.setValue('variableName', response.id);

}

}

Regards
Harish

Aniket Chavan
Tera Sage
Tera Sage

Hello @kranthi2 ,

You can achieve this by setting auto populate field as well as with one OnChange Client script and script include, please refer the code below and let me know how it works for you.

Script Include (Name: "AutoPopulateScript"):

 

var AutoPopulateScript = Class.create();
AutoPopulateScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getRequestorDetails: function() {
        var userData = {};
        var userCcid = '';
        var SysID = this.getParameter('sysparm_sysid'); // opened for sysid
        var user = new GlideRecord('sys_user');
        user.addQuery('sys_id', SysID);
        user.query();
        
        if (user.next()) {
            userCcid = user.getValue('ccid'); // ccid field from user table
            var cid = new GlideRecord('ccid_table'); // ccid table
            cid.addQuery('ccid', userCcid);
            cid.query();

            if (cid.next()) {
                userData.cid = user.getValue('u_uid');
                userData.address = cid.getValue('address');
                userData.id = cid.getValue('symphony_id');
            }
        }

        return JSON.stringify(userData);
    },

    type: 'AutoPopulateScript'
});

 

 

Client Script (Type: onChange):

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var si = new GlideAjax('AutoPopulateScript');
    si.addParam('sysparm_name', 'getRequestorDetails');
    si.addParam('sysparm_sysid', newValue);
    si.getXMLAnswer(parseResponse);

    function parseResponse(answer) {
        var response = JSON.parse(answer);

        g_form.setValue('issue_location', response.address); // Replace 'issue_location' with your actual field name
        g_form.setValue('ccid_field', response.cid); // Replace 'ccid_field' with your actual field name
        g_form.setValue('simphony_id', response.id); // Replace 'simphony_id' with your actual field name
    }
}

 


Please let me know your views on this and Mark
Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket