The CreatorCon Call for Content is officially open! Get started here.

Make different server action based on Button clicked in UI page modal

Nico12
Mega Sage

Hi,

 

I have a Ui action on the alm_hardware table. When this button is clicked, a Modal UI Page appear with some validation to do.

 

I have 3 buttons : 

Button 1 : Validate and do nothing (just a checkbox that will be unchecked and state that change).

Button 2 : Validate and update the asset (some fields are updated and some other actions).

button 3 : cancel (close the modal).

 

I know that when you have 2 buttons you can call the server side actions in  UI action with gsftSubmit(null, g_form.getFormElement(), 'update');

But how you can distinguish that the user has clicked on the button 1 or button 2  from server side and then do nothing or update ?

 

Regards,

1 ACCEPTED SOLUTION

@Nico12 

why not put the code of UI action in ui page itself?

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Nico12 

all those buttons will be on UI page, have unique HTML ids for those and you can determine which one was clicked

what did you start with and where are you stuck?

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

Hi Ankur,

 

I have these 3 buttons on the UI Page :

 

UI PAGE HTML

 

<div class="row">
		<div class="col-sm-4">
			<button class="topIconEffect1 zoom-on shadow top_icon" id="cancel_button" onclick="return onCancel()" type="submit">
				<h2>Annuler</h2>
			</button>
		</div>
		<div class="col-sm-4">
			<button class="topIconEffect2 zoom-on shadow top_icon" id="ok_button" onclick="return dontUpdate()" type="submit">
				<h2>Valider l'affectation sans mettre à jour l'asset</h2>
			</button>
		</div>
		<div class="col-sm-4">
			<button class="topIconEffect3 zoom-on shadow top_icon" id="erase_button" onclick="return Update()" type="submit">
				<h2>Update</h2>

			</button>
		</div>
	</div>

 

 

 

UI PAGE CLIENT SCRIPT

 

function update() {
	gsftSubmit(null, g_form.getFormElement(), 'Update'); // Server side of UI Action
}

function dontUpdate(){
	removecheckBox();
}

function onCancel() {
	closeGlideModal(); // if cancel, close modal box
}

 

The removeCheckBox() is a function on the Client side of the UI Action

 

 

My Question is how i can write condition server side if button 1 or button 2 have been clicked.

 

UI ACTION SERVER SIDE SCRIPT

 

If button Update clicked
Do this
and this on the asset form


If button dontUpdate clicked
Do that
and Do that on the asset form

 

 

 

 

 

@Nico12 

why not put the code of UI action in ui page itself?

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

Nico12
Mega Sage

Hi Ankur,

 

You are right. I don't know why i was trying to come back to the UI Action.

I did it from the UI Page directly.

Thanks!