Copy Values from another Table into a Form without saving?

shawn_h
Tera Guru

Hi folks,

Hope you can help!

I'm looking for a way to copy field entries I have in a custom table into an incident form, but ideally I'd want to be able to copy the entries and not save them/create a record, more so they appear within the fields and the user has the option to save/edit them before continuing. 

I currently have an extra referenced field linking to my custom table, and a UI action that pulls in those fields. The downside is I've done this wrong as it saves and creates the record also.

Essentially i'm looking for a way of emulating the functionality of templates, but cannot actually use templates for this purpose (unless it's possible to link templates into this other table, and call them that way, but I'd prefer another solution if there is one!)

find_real_file.png

16 REPLIES 16

Abhijeet Upadhy
Tera Expert

Hello shawn.h

 

You need create a client callable UI Action. In the script call an ajax to pull the value from your custom table and using g_form.setValue set those values and at the end of the function call "return false".

 

Thanks

Abhijeet Upadhyay

Thanks Abhijeet! That sounds on the right lines, will try this one out 🙂 

Please mark the answer as correct or helpful as the case may be :)..

UI Action:

onclick: copy_values()

Script:

function copy_values()

{

var table = "table_name"; // name of the custom table comes here

 

var ga = new GlideAjax("copy_values")

ga.addParam("sysparm_name", "copy_values");

ga.addParam("sysparm_table", table);

ga.addParam("sysparm_sys_id", g_form.getVaue("name of reference field comes here"));

ga.getXMLWait();

var answer = ga.getAnswer();

 

answer = answer.split(",");

 

g_form.setValue("field1 on incident form", answer[0]);

g_form.setValue("field2 on incident form", answer[1]);

//and so on

return false;

}

 

Script Include:

Name: copy_values

Script:

var mandatory = Class.create();
mandatory.prototype = Object.extendsObject(AbstractAjaxProcessor, {
copy_values: function() {

var table = this.getParameter(sysparm_table);

var sys_id = this.getParameter(sysparm_sys_id);

var answer = "";

 

var gr = new GlideRecord(table);

gr.addQuery("sys_id", sys_id);

gr.query();

if(gr.next())

{

answer = answer + gr.field_name1 + "," + gr.field_name2 + ",";//all the fields value comes here comma seperated

}

 

return answer;
},
type: 'copy_values'
});

 

NOW YOU CAN MARK THE ANSWER AS CORRECT ;)..