- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 09:40 PM
Hi All,
Need help/Suggestion
The query is when I click on the UI action, the condition need to check no product assigned is false, get the display of the parent , based on the parent display value need to populate number from the cmdb_ci_service_business table.
The below code is populating the alert display name but not populating the number.
When I use the same code in back ground script it is working, please let me why it is not working in the UI action client callable.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 09:46 PM
Hi @Madhusagar Pal1 ,
If u have checked the client checkbox on the UI action then GlideRecord won't work as the UI action will behave like a client script. U can call a script include from the UI action using GlideAjax to perform that operation. This is one way.
Else what u can do is uncheck the checkbox for client,this way ur UI action will behave as a server side script n then u can do something like below.
if (current.noProductAssigned === "false") {
var digitalProduct = current.parent.getDisplayValue();
//alert("digital product value in form: " + digitalProduct);
//instead of alert u can use gs.info n try to print the logs
var digiProd = new GlideRecord('cmdb_ci_service_business');
digiProd.addQuery('name', digitalProduct);
digiProd.query();
while (digiProd.next()) {
var digitalProductNum = digiProd.getValue('number');
}
//alert("digital product number is : " + digitalProductNum);
//Use gs.info to print logs as it's a server side script now. Alert can only be used at client side.
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 09:38 PM - edited 01-30-2024 09:41 PM
Then you should make use of if. You can alter it like :
if (tax_nod.next()) {
var prdouctGroupID = tax_nod.getDisplayValue('u_product_group_id');
gs.info('Product Group ID using name :' + prdouctGroupID);
return prdouctGroupID;
}
About your problem, I assume that productGroupID is one of your catalog variable. If you want to set the value of the catalog variable, you should make use of
g_form.setValue('productGroupID',answer);
Can you please check on this
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 09:48 PM
Are you getting any output from the alert you have kept ? alert("digital product value in form: " + digitalProduct);
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 09:59 PM
Yes, I am getting the display name of the parent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 10:20 PM - edited 01-29-2024 10:22 PM
Hello @Madhusagar Pal1
You can use client side as well as server side script in UI action.
You have to consider below points :
1.Action name should be there
2.Client is checked
3.onClick - function name
For example,
I have created one UI action on incident form 'Update cmdb' , when user clicks on button One pop will get displayed..& one record from alm_hardware will get updated.
Button :
When user clicks button pop will get displayed.
When user clicks on OK , record from Hardware table gets updated.
Here is UI action script :
/*1.When user clicks on button below function will get executed*/
function clientUpdateCmdb() {
var message = confirm("Confirm incident number=" + g_form.getValue('number'));
/*1.1 Once user clicks on OK in pop up same UI action will get invoked using action name but this time only Server side code will run */
if (message == true) {
gsftSubmit(null, g_form.getFormElement(), 'update_cmdb'); //action name
}
}
/*2. Server side code will run */
serverUpdate();
function serverUpdate(){
var gr = new GlideRecord('alm_hardware');
gr.addQuery('sys_id','00a96c0d3790200044e0bfc8bcbe5dc3');
gr.query();
if(gr.next()){
gr.asset_tag = 'P123456789';
gr.update();
}
}
**You can adjust your code accordingly and use condition field as per your need
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates