autopopulate field

Shir Sharvit
Tera Contributor

I added to the incident table a field called call back (u_call_back) of string type.
I need to autopopulate this field with the caller's mobile phone as default value.

ShirSharvit_0-1701252231451.png

 

What is the problem with the code?

ShirSharvit_1-1701252355680.png

 

 

7 REPLIES 7

Anil Lande
Kilo Patron

Hi,

Have you tried running this script in background script? Make sure the person you are impersonating has some value in Call Back Field on User record.

Also you mentioned that you want to populate it based on Caller then you need to remove gs.getUserID and replace it with current.caller_id.

Also Default value will be set when user open form to create new record and Form is saved in Database. It will not update values when user change caller field in Form view.

Why don't you use same logic used for Mobile phone field added on your form?

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Can you please write me the solution way for this

Default vaue doesnt work when the value is getting change. It doesnt work on OnChange.

 

I would recommend write the OnChange client on caller and it will populate the phn number by using g_form.getReference() or GlideAjax.

 

See the code below

 

Regards,

Shamma

Regards,Shamma Negi

 

Client Script

function getServerData() {
var ga = new GlideAjax('ScriptIncludeName'); // Replace 'ScriptIncludeName' with the name of your script include
ga.addParam('sysparm_name', 'getServerData'); // Specify the method name to run on the server
ga.addParam('sysparm_data', 'some data to pass to the server'); // Optional: add additional data to pass to the server
ga.getXML(responseHandler); // Send the request and specify the function to run when the response is received
}

function responseHandler(response) {
var responseXML = response.responseXML;
var serverData = responseXML.documentElement.getAttribute('server_data'); // Get the data returned from the server
// Do something with the server data
}

Script Include

var ScriptIncludeName = Class.create();
ScriptIncludeName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// This method is called by GlideAjax when the client script calls it
getServerData: function() {
var data = this.getParameter('sysparm_data'); // Get the data passed from the client script
// Do something with the data
var serverData = 'some data to return to the client script';
this.response.setContentType('text/xml');
this.response.write('<server_data>' + serverData + '</server_data>'); // Set the data to be returned to the client script
}
});

 

 

Using g_form.getReference then this code

 

      var caller = g_form.getReference('caller_id', popCallerInfo);

 

function popCallerInfo(caller){
      //Location setting section
      if(loc && !isLoading && newValue != oldValue){
         g_form.setValue('location', caller.location);
      }

Regards,Shamma Negi