UI action button dialog box requirement

Rose17
Tera Contributor

Hi All,

 

I have a requirement to create button on a custom table. Whenever the user clicks on the button, it should open a pop up saying ‘Do you want to proceed?’ with Ok and Cancel button.

When the user clicks on Ok button, it should insert a new record and redirect to the new record form copying the fields values of previous record. Fields like number and additional comments should be copied in the new record from previous record.

When the user clicks on Cancel button, it should abort the action and close the pop up.

 

Could some one help me to achieve this requirement?

Any help is appreciated.

 

Thanks in advance.

1 ACCEPTED SOLUTION

@Rose17 

I won't recommend using GlideRecord into client side

so try something like this

function myAction()
{
	if(confirm("Do you want to proceed?")==true){
		gsftSubmit(null, g_form.getFormElement(), "Action name")
	}
}

if(typeof window == 'undefined')
	createReq();

function createReq() {
	var gr = new GlideRecord('custom_table_name');
	gr.initialize();
	gr.newRecord();
	gr.number = current.number;
	gr.comments=current.comments;
	var newID = gr.insert();
	action.setRedirectURL(gr);
	action.setReturnURL(current);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

16 REPLIES 16

New record is getting inserted, but values of previous record fields are not getting copied into 'number' and 'additional comments' fields.

Also number is getting incremented every time new record is getting inserted.

Kindly help here.

Hi @Rose17 

 

Try it like this.

function myAction()
{
	if(confirm("Do you want to proceed?")==true){
		gsftSubmit(null, g_form.getFormElement(), "Action name")
	}
}

if(typeof window == 'undefined')
	createReq();

function createReq() {
	var gr = new GlideRecord('custom_table_name');
	gr.initialize();
	gr.number = current.getValue('number');
	gr.comments=current.comments.getJournalEntry(1);
	var newID = gr.insert();
	action.setRedirectURL(gr);
	action.setReturnURL(current);
}

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.