Displaying alert when ui action is used and was successful

samadam
Kilo Sage

I am trying to display an alert when ui action is used and was successful. How can I do this?

Tried to get the action name and check the state change but that doesnt work. I am trying this onSubmit client script. Tried to check if state changed using  var field1 = g_form.getControl('caller_id'); and if(field1.changed) but no luck. Any ideas?

1 ACCEPTED SOLUTION

If condition typeof window == 'undefined' is true, then for sure you don't have alert()* available.

 

Back to your original problem, there is no possibility to check that stuff has been updated or not.

I mean you could come up with some cumbersome way to somehow gather changes client side, serialize the changes and store those into some special field also saved in the same go, then on server side, after executing current.update() reload the record into a GlideRecord, extract the packed changes and compare the two, but this can get quickly super complicated and produce false positives.

Like what if you have business rules forcing certain values that override the changes made by the user?

Is that something considered an error, or is it not an error?

Not to mention you'd need to find a way to know if a change has been overridden by a rule or if it did not happen because of some error.

 

Therefore, in my opinion what you could do is to show an info message if the transaction has not been cancelled.

If a transaction does get cancelled, the process cancelling the transaction shall also present some error message, so you should not concern yourself with implementing the error message.

When I say transaction, I mean current being updated.

Something like:

if (typeof window == 'undefined') {
	// Do other stuff you want to do before updating the record;
	current.update();

	// If for some reason (Business Rule or Data Policy) the update
	// is cancelled do not show the info box about success
	if (!current.isActionAborted())
		gs.addInfoMessage('Changes have been saved');
}

 

B.t.w. slightly off topic, but the recommended way to inform the users (by every UX expert and even SN) is showing info messages NOT by alert()-ing.

Server side one would use

gs.addErrorMessage()
gs.addInfoMessage()

while client side (in (Catalog) Client Scripts - Portal widget Client controllers use a different mechanism)

g_form.addInfoMessage()
g_form.addErrorMessage()
g_form.showFieldMsg()

 

*) You could in theory define a Script Include or global Business Rule that implements the alert function server side, but I believe that is not what you had in mind.

View solution in original post

4 REPLIES 4

Kristen Ankeny
Kilo Sage

Why not add the code to the ui action itself?

Tried that but did not work.

 
if(typeof window == 'undefined'){
submit2Review();
alert('after submit');
}

If condition typeof window == 'undefined' is true, then for sure you don't have alert()* available.

 

Back to your original problem, there is no possibility to check that stuff has been updated or not.

I mean you could come up with some cumbersome way to somehow gather changes client side, serialize the changes and store those into some special field also saved in the same go, then on server side, after executing current.update() reload the record into a GlideRecord, extract the packed changes and compare the two, but this can get quickly super complicated and produce false positives.

Like what if you have business rules forcing certain values that override the changes made by the user?

Is that something considered an error, or is it not an error?

Not to mention you'd need to find a way to know if a change has been overridden by a rule or if it did not happen because of some error.

 

Therefore, in my opinion what you could do is to show an info message if the transaction has not been cancelled.

If a transaction does get cancelled, the process cancelling the transaction shall also present some error message, so you should not concern yourself with implementing the error message.

When I say transaction, I mean current being updated.

Something like:

if (typeof window == 'undefined') {
	// Do other stuff you want to do before updating the record;
	current.update();

	// If for some reason (Business Rule or Data Policy) the update
	// is cancelled do not show the info box about success
	if (!current.isActionAborted())
		gs.addInfoMessage('Changes have been saved');
}

 

B.t.w. slightly off topic, but the recommended way to inform the users (by every UX expert and even SN) is showing info messages NOT by alert()-ing.

Server side one would use

gs.addErrorMessage()
gs.addInfoMessage()

while client side (in (Catalog) Client Scripts - Portal widget Client controllers use a different mechanism)

g_form.addInfoMessage()
g_form.addErrorMessage()
g_form.showFieldMsg()

 

*) You could in theory define a Script Include or global Business Rule that implements the alert function server side, but I believe that is not what you had in mind.

SanjivMeher
Kilo Patron
Kilo Patron

I think you can use a combination of display business rule and client script.

In the display business rule you can populate a g_scratchpad variable if all the conditions met and then use that variable in onSubmit Client Script to create an alert.


Please mark this response as correct or helpful if it assisted you with your question.