Create Incident Record producer while selecting contact phone details sometimes show wrong.

AshishD18291065
Tera Contributor

Create Incident Record producer while selecting contact phone details sometimes show wrong data in fields. And date get populate to fields from the client script. 

 function callbackdata(response) {
        var answer = response;
        var push = JSON.parse(answer); //setting user details into variables
            g_form.setValue('mobile_phone', push.mobile_phone);
            g_form.setValue('business_phone', push.phone);
    }
Both details are taking from the User table for the person who try to raise the incident ticket. Sometimes its show the correct data and sometimes its shows the wrong data for person who want to raise a ticket. Need to know why its working like this. Sometimes facing issue and sometimes no issue. 
5 REPLIES 5

Community Alums
Not applicable

Hi @AshishD18291065 

 

Can you please try push.mobile_phone.toString() and check that.

 

Thanks 

Sarthak

luffy3478
Tera Guru

post full client script and script include

AshishD18291065
Tera Contributor

Script Include:


var Details = Class.create();
Details.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var obj = {};
obj.mobile_phone = "";
obj.phone = "";
var requestedforSysID = this.getParameter('sysparm_openFor');
var grObj = new GlideRecord("sys_user");
grObj.addQuery("sys_id", requestedforSysID); //comparing sysID
grObj.query();
if (grObj.next()) { //getting user details
obj.mobile_phone=grObj.getValue("mobile_phone");
obj.phone = grObj.getValue("phone");
}

var data = JSON.stringify(obj);
return data;
},

type: 'Details'
});

 

 

Client Script :

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

var openFor = g_form.getValue('caller_id'); //gettin sysID of requestedFor
var abc = new GlideAjax('Details'); // script include name
abc.addParam('sysparm_name', 'getDetails'); //function name
abc.addParam('sysparm_openFor', openFor); //pushing requestedFor sysID into server side
abc.getXMLAnswer(callbackdata);

 function callbackdata(response) {
        var answer = response;
        var push = JSON.parse(answer); //setting user details into variables
            g_form.setValue('mobile_phone', push.mobile_phone);
            g_form.setValue('business_phone', push.phone);
    }

}

 

Subhashis Ratna
Tera Guru

Hi @AshishD18291065 

I have tried your Script logic and getting expected output .

SubhashisRatna_0-1712757169626.png

 

var obj = {
    mobile_phone: "",
    phone: ""
};

var grObj = new GlideRecord("sys_user");
grObj.addQuery("sys_id", '292bebbd9749d1101f1b30200153af5f');// Replace with the desired sys_id
grObj.query();

if (grObj.next()) {
    obj.mobile_phone = grObj.getValue("mobile_phone"); //Here you can use .toString() Method
    obj.phone = grObj.getValue("phone"); //Here you can use .toString() Method
}
var data = JSON.stringify(obj);
gs.print("Data: " + data);
var push = JSON.parse(data);
gs.print("Mobile Phone: " + push.mobile_phone + ''); 
gs.print("Phone: " + push.phone + '');


If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

Thanks,
Subhashis Ratna