How to control errors with UI actions

Yuki21
Tera Expert
Hi.
Please tell me how to realize it when doing the following with UI actions.
How can I fill in the script field to display an error on the screen when the button is pressed and interrupt the process?
(★)
var username =current.u_reference_1; //ユーザーID
var password=current.u_string_2;  //上記のユーザーのパスワード
var authed= GlideUser.authenticate(username,password); 

if (authed == true) {
    current.state='approved';
    current.update();
    new ApprovalUserFeedback().approved(current);	
    gs.info('以下のユーザで承認が行われました。\n<対象>\nユーザID=' + username + '\n要求アイテム番号=' + current.document_id);
}else{
    g_form.showErrorBox('エラー');
	gs.info('ユーザIDとPWが異なります。\n<対象>\nユーザID=' + username);
}
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

g_form won't work if your UI action is server side

you can show error message like this but it would be on form and not besides field

var username =current.u_reference_1; //ユーザーID
var password=current.u_string_2;  //上記のユーザーのパスワード
var authed= GlideUser.authenticate(username,password); 

if (authed == true) {
    current.state='approved';
    current.update();
    new ApprovalUserFeedback().approved(current);    
    gs.info('以下のユーザで承認が行われました。\n<対象>\nユーザID=' + username + '\n要求アイテム番号=' + current.document_id);
}else{
    gs.addErrorMessage('エラー');
    gs.info('ユーザIDとPWが異なります。\n<対象>\nユーザID=' + username);
}

OR

If you want to show error near field then you will have to make the UI action Client + Server both using gsftSubmit()

Client & Server Code in One UI Action

Regards
Ankur

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

g_form won't work if your UI action is server side

you can show error message like this but it would be on form and not besides field

var username =current.u_reference_1; //ユーザーID
var password=current.u_string_2;  //上記のユーザーのパスワード
var authed= GlideUser.authenticate(username,password); 

if (authed == true) {
    current.state='approved';
    current.update();
    new ApprovalUserFeedback().approved(current);    
    gs.info('以下のユーザで承認が行われました。\n<対象>\nユーザID=' + username + '\n要求アイテム番号=' + current.document_id);
}else{
    gs.addErrorMessage('エラー');
    gs.info('ユーザIDとPWが異なります。\n<対象>\nユーザID=' + username);
}

OR

If you want to show error near field then you will have to make the UI action Client + Server both using gsftSubmit()

Client & Server Code in One UI Action

Regards
Ankur

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

thank you!

There is no problem displaying an error on the form.
The error message is displayed after transitioning to the list view instead of the input screen.
Is it possible to display the error message on the input screen?

gs.addErrorMessage('Error Message');
action.setRedirectURL(current);

Create a UI action (servicenow.com)

As part of a UI action script, you can redirect a user to a URL. For example, you might add links to a form or open a new record after it is created from a UI action. To redirect a user to a URL from a UI action, use this syntax in the Script field to define the redirect link:

    action.setRedirectURL ( 'http://www.mysite.com/mypage.htm' );

To direct a user to a record, use this syntax, where new_record is the variable name for the GlideRecord:

    action.setRedirectURL (new_record );