How to create a Button on Catalog item

AbdulAzeez
Mega Guru

Hello Everyone,

We have a requirement where we need to create a Button on Catalog item once the user enter details once the user click on the button it should redirect to some 'x' table and write those records.

It should work on Catalog & as well as Serive Portal

1 ACCEPTED SOLUTION

Hello Azeez,



I have tried below code in Serviceportal and it worked for me.



HTML:



<input type="text" name="name" ng-model="inputValue" />


<button type="button" class="btn btn-danger btn-block" ng-click="c.setFieldValue(inputValue)">Value</button>



Client Controller:



function($scope) {


var c = this;


c.setFieldValue = function(uploadname) {


var g_form = $scope.page.g_form;


if (g_form.getValue('a1') != '') { // a1, a2 Replace with your variable names


g_form.setValue('a2', g_form.getValue('a1'));


g_form.clearValue('a1');



}


else {


g_form.setValue('a2', $scope.inputValue);


$scope.inputValue = '';


}


}



Reference:


Service Portal: Catalog Item Buttons — ServiceNow Elite



Thank You


Srikanth


View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Abdul,



So you want the button on the page for catalog item where all other variables are also present?



Regards


Ankur


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

Correct Ankur,



Once the user the opens the item after entering all the details if the user press the button it should write in X table,


Hi Abdul,



In this scenario you will require either UI page or UI macro as variable and have button in the html section.



Regards


Ankur


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

Thanks Ankur,



I already created a button using UI page but where i got struck is how to pass all the variables info into the table;