How to Display an alert in Record producer if form variable value not matched in table

vsharma
Tera Contributor

Hi All:

I have a Record producer (table - u_visitor with fields - Name/ mobile no/ checkin time/ checkout time/ state) where I need to check mobile number and if it matches in table then user state change to "checked out" else alert user to check mobile number and abort.

I tried but not able to get else condition work to alert user & abort process. Please suggest.

 

—— Record Producer Script section -------

var mno = producer.u_mobile_number;

var rec = new GlideRecord('u_visitor');

rec.addQuery('u_mobile_number', mno);

rec.query();

 

if (rec.next()) {

rec.u_state = 'checkedout';

rec.u_checkout_time = current.u_checkout_time;

rec.update();

current.setAbortAction(true);

Note: All RP form fields mapped to table fields.

 

Thanks

1 ACCEPTED SOLUTION

I just noted that this was a record producer. You could directly with the producer script. Can you please try this once after deactivating the client script and see if it works?

var mno = producer.u_mobile_number;
var rec = new GlideRecord('u_visitor');
rec.addQuery('u_mobile_number', mno);
rec.query();
if (rec.next()) {
rec.u_state = 'checkedout';
rec.u_checkout_time = current.u_checkout_time;
rec.update();
}else{
gs.addErrorMessage("Update Mobile number First");
current.setAbortAction(true);
//producer.redirect =""; 
} 

View solution in original post

28 REPLIES 28

Hi, 

I have tried this & when wrong mobile number is entered - Value is getting cleared, alert is coming but still a new entry is getting created.

In addition, when mobile number is matched even then a new entry is created. However, it should update the existing record state with checked out time.

Thanks

I just noted that this was a record producer. You could directly with the producer script. Can you please try this once after deactivating the client script and see if it works?

var mno = producer.u_mobile_number;
var rec = new GlideRecord('u_visitor');
rec.addQuery('u_mobile_number', mno);
rec.query();
if (rec.next()) {
rec.u_state = 'checkedout';
rec.u_checkout_time = current.u_checkout_time;
rec.update();
}else{
gs.addErrorMessage("Update Mobile number First");
current.setAbortAction(true);
//producer.redirect =""; 
} 

You can also add a URL for producer.redirect as =

producer.redirect= "com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=SYS_ID_OF_YOUR_RECORD_PRODUCER"

Just not that the error message would be highlighted to user on top of the screen as a message and not a popup. 

Thanks a bunch. I was looking for alert but I think that will not work here so for now Error message will serve the purpose. I was simply missing this else part.

But yes, producer.redirect did not work on service portal.

Glad it worked!

For the redirect to work in portal, you could add something like this to check on the URL to see if you are in portal then redirect to portal link else on the ITIL view

var url = gs.action.getGlideURI();
if(url.indexOf("/Your portal suffix Here/") > -1){
  producer.redirect= "Portal URL for record producer";
}else{
  producer.redirect= "com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=SYS_ID_OF_YOUR_RECORD_PRODUCER";
}