- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 03:56 PM
When receiving a PO, there is an associated Asset Order Line (AOL).
On the PO, there is a UI Action 'Receive'.
If the Product Model is missing, we want the receive button to be hidden completely, or we want an error message to display that says something like "Please populate the Product Model in order to receive this line item".
In the UI action server script, I want to first query for an associated line item and check that field. If product model (or AOL) is empty, then just display an error saying so. Below is what I wrote but it doesn't seem to be doing the checks at all and goes right to the modal.
var currentRecord = current;
var assetOrderLines = new GlideRecord('proc_po_item');
assetOrderLines.addQuery('purchase_order', currentRecord.sys_id); // Asset Order
assetOrderLines.query();
// Check if there are associated Asset Order Lines
if (assetOrderLines.hasNext()) {
while (assetOrderLines.next()) {
// Check if the Product Model field is empty for any of the Asset Order Lines
if (assetOrderLines.model.nil()) {
// Display an error message and exit the script
gs.addErrorMessage("Please populate the Product Model in order to receive this line item");
}
}
}
function openPopUp(){
var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
var dialog = new dialogClass("receive_order");
dialog.setWidth("800");
dialog.setTitle("Receive Purchase Order #" + g_form.getValue("number"));
dialog.setPreference("sys_id", g_form.getUniqueValue());
dialog.render(); // Open the dialog box
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 06:50 PM
To hide the UI Action, you can use the condition field in UI Action.
1. Create a script include and a function in it like the one below.
var CustomAolUtils = Class.create();
CustomAolUtil.prototype={
initialize :function(){},
checkForEmptyModelInAOL : function(currentRecord){
var assetOrderLines = new GlideRecord('proc_po_item');
assetOrderLines.addQuery('purchase_order', currentRecord.sys_id);
assetOrderLines.query();
if (assetOrderLines.hasNext()) {
while (assetOrderLines.next()) {
var model = assetOrderLines.getValue('model');
if (gs.nil(model)) {
return false;
}
}
return true;
}
return false;
},
type :'CustomAolUtil'
};
Then use this UI Action condition like this,
new CustomAolUtils.checkForEmptyModelInAOL(current);
In this way you can completely hide the UI Action if there is any AOL with empty model.
Please mark my answer helpful and accept as solution if it helped you 👍✅
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 06:50 PM
To hide the UI Action, you can use the condition field in UI Action.
1. Create a script include and a function in it like the one below.
var CustomAolUtils = Class.create();
CustomAolUtil.prototype={
initialize :function(){},
checkForEmptyModelInAOL : function(currentRecord){
var assetOrderLines = new GlideRecord('proc_po_item');
assetOrderLines.addQuery('purchase_order', currentRecord.sys_id);
assetOrderLines.query();
if (assetOrderLines.hasNext()) {
while (assetOrderLines.next()) {
var model = assetOrderLines.getValue('model');
if (gs.nil(model)) {
return false;
}
}
return true;
}
return false;
},
type :'CustomAolUtil'
};
Then use this UI Action condition like this,
new CustomAolUtils.checkForEmptyModelInAOL(current);
In this way you can completely hide the UI Action if there is any AOL with empty model.
Please mark my answer helpful and accept as solution if it helped you 👍✅
Anvesh