Need to use variables from client side function in server side function on an UI action.

Reddymahesh
Tera Contributor

I am working on an UI action button, In which I need to use variables from client side function in next server side function . But I am getting undefined values in the description

Below is the code of UI action

///////////////////////////////////////////////////////////////////////////////////////////////////

 

var FirstName;
var LastName;

function ChangeName() {
    FirstName = prompt("Enter Firstname");
    LastName = prompt("Enter Lastname");
    if (FirstName && LastName) {
        alert('Name captured is ' + FirstName + " " + LastName);
    }
    gsftSubmit(null, g_form.getFormElement(), "user_change_name");
}

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

function updateItem() {
    var gr = new GlideRecord('sc_req_item');
    gr.initialize();
    gr.assignment_group = '4a1d990547056510d2c3b604836d432e'// ServiceNow admin team
    gr.description = 'Change the name to: ' + FirstName + ' ' + LastName;
    gr.insert();
    action.setRedirectURL(current);
}
1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Reddymahesh ,

 

If you want to add to Workspace there is a Workspace tab where you can choose Workspace Form Button to make the UI action appear on the line of UI actions, or Workspace Form Menu to make it appears as a list item in the menu list.

 

If the code for the UI action I provided earlier works for the creation of RITM and can populate description successfully could you please mark the answer as correct? Thank you

View solution in original post

15 REPLIES 15

Community Alums
Not applicable

Hi @Reddymahesh ,

 

If you are doing it in scoped app, call Script include like this: 

var ga = new GlideAjax('API name');

 

Community Alums
Not applicable

Hi @Reddymahesh ,

 

Did you make it work by calling your script include with scope app and name as my response above? Looking forward to see if I can assist with anything

Reddymahesh
Tera Contributor

Hi @Community Alums ,

 

Thanks for your reply. Can we add this UI action to a landing page?. 

Community Alums
Not applicable

Hi @Reddymahesh ,

 

If you want to add to Workspace there is a Workspace tab where you can choose Workspace Form Button to make the UI action appear on the line of UI actions, or Workspace Form Menu to make it appears as a list item in the menu list.

 

If the code for the UI action I provided earlier works for the creation of RITM and can populate description successfully could you please mark the answer as correct? Thank you

I want to add it be added to a  landing page not on any workspace, We need to do it through UI builder. Any idea on how to achieve this