autopopulate field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 02:06 AM
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.
What is the problem with the code?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 02:13 AM
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?
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 02:29 AM
Can you please write me the solution way for this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 02:54 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 02:58 AM
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);
}