How to create macro button in servicenow portal form

VIKAS MISHRA
Tera Contributor

I wanted to create a macro button on portal form named as "ADD', and if we click on add button then it should automatically copy the value mentioned in another variable "Description" and add this value in another exiting Multirow variable as a record. 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@VIKAS MISHRA 

UI macros won't work on portal as it's not supported.

You can use widget and associate it with variable of type Custom and then handle the logic when click copy the value.

see this and enhance

Service Portal Widget - grabbing variable value on change in Client Script and passing to Server Scr... 

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

M Iftikhar
Mega Sage

Hi @VIKAS MISHRA ,

The best way to handle this on the Service Portal is by using a Catalog Client Script tied to a custom “ADD” button. You should use the supported addRow() API for the Multi-Row Variable Set (MRVS).

Here’s a recommended script example:

function onClick()
{ var descriptionValue = g_form.getValue('description_variable_name');
if (!descriptionValue)
{
g_form.showFieldMsg('description_variable_name', 'Description cannot be empty.', 'error');
return;
}
var mrvsControl = g_form.getControl('multi_row_variable_set_name');
var newRow = { 'mrvs_variable_name': descriptionValue // MRVS variable internal name }; mrvsControl.addRow(newRow); // Optional: clear description field after adding g_form.setValue('description_variable_name', '');
}
 
  • Uses addRow() which is officially supported for MRVS
  • Simpler, more maintainable code
  • Straightforward to implement without building full custom widgets

 

Useful References

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.