UI Action to create independent record ... ?

Zod
Giga Guru

Hi Experts,

I'm using a UI action on a from to "copy" some of the fields and to new record that is to be created on a completely independent table.

Could anyone please help me with this?

Something like this I had in mind ... but missing the // CODE ??? part

****

function clickedReview() {

    gsftSubmit(null, g_form.getFormElement(), 'action_name');

        }

// Code that runs without 'onclick'

// Ensure call to server side function with no browser errors

if (typeof window == 'undefined')

    createNew();

function createnew() {

    // CODE ????

   

    current.update();

    gs.addInfoMessage(gs.getMessage("Record added"));

    action.setRedirectURL(current);

}

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,



You can use the below Script in your UI Action



Script:



var x= new GlideRecord("change_request");     //Replace your Desired Target Table


x.initialize();


x.short_description = current.short_description;


x.assignment_group='Enter Sys Id';


x.insert();


action.setRedirectURL(current);


gs.addInfoMessage('Record <a href ="/Table_Name.do?sysparm_query=number%3D' + x.number + '">'+ x.number +'</a>'+ 'has been created.');



find_real_file.png



Similarly you can have other fields as it has been mentioned for Short Description and Assignment Group. In the above screenshot Replace Demand with your Table Name on which you want this UI Action to be present on the form.




Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

2 REPLIES 2

shloke04
Kilo Patron

Hi,



You can use the below Script in your UI Action



Script:



var x= new GlideRecord("change_request");     //Replace your Desired Target Table


x.initialize();


x.short_description = current.short_description;


x.assignment_group='Enter Sys Id';


x.insert();


action.setRedirectURL(current);


gs.addInfoMessage('Record <a href ="/Table_Name.do?sysparm_query=number%3D' + x.number + '">'+ x.number +'</a>'+ 'has been created.');



find_real_file.png



Similarly you can have other fields as it has been mentioned for Short Description and Assignment Group. In the above screenshot Replace Demand with your Table Name on which you want this UI Action to be present on the form.




Hope this helps.Mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

SanjivMeher
Kilo Patron
Kilo Patron

Try below



ta = new GlideRecord('table_name');


ta.fieldname1= current.fieldname1;


ta.fieldname2= current.fieldname2;


ta.fieldname3= current.fieldname3;


ta.fieldname4= current.fieldname4;


ta.insert();


action.setRedirectURL(ta);



Please mark this response as correct or helpful if it assisted you with your question.