- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2023 11:24 PM - edited ‎02-22-2023 11:36 PM
I have requirement to create ui action named "review" it should visible to only the users who is the reviewer field on the form. and When the review button is pressed it's supposed to evaluate whether there's a screenshot of the certification verification. for this i have created a ui action and gave the condition like "current.x_613789_myprofile_career.reviewers.toString().indexOf(gs.getUserID()) > -1"
but the ui action is visibling all the time on form it shouldn't visible for everyone. when i click the ui action it's not operating any action. seems code is not working for attachement check.
i have attached the ui action and code.
function checkAttachment() {
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", "career");
att.query();
if (!att.next()) {
alert("Please attach the screenshot of the certification verification.");
return false;
}
return true;
}
Thanks In Advance @BharathChintala
@Ankur Bawiskar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2023 04:59 AM - edited ‎02-27-2023 07:19 AM
In Condition give below
on click should be empty(that means no client script only Server we will be writing.
current.reviewers.indexOf(gs.getUserID()) > -1
also update script as below
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", current.getTableName());
att.addQuery('table_sys_id', current.getUniqueValue());
att.addEncodedQuery('content_typeSTARTSWITHimage');
att.query();
if(!att.next()) {
gs.addErrorMessage("Please attach the screenshot of the certification verification.");
current.setAbortAction(true);
}else{
you can write script link update or insert what you want to do here if there is attachment
}
Bharath Chintala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2023 12:43 AM
your UI action runs on client side so current object won't work
Uncheck the client checkbox
Remove the onClick function
Use this script
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", current.x_613789_myprofile_career);
att.addQuery('table_sys_id', current.getUniqueValue());
att.addEncodedQuery('content_typeSTARTSWITHimage');
att.query();
if(!att.next()) {
gs.addErrorMessage("Please attach the screenshot of the certification verification.");
current.setAbortAction(true);
}else{
current.state = 'completed';
current.update();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2023 11:37 PM
UI action is client side or server side? share screenshot
condition looks fine
are you sure the field name is correct?
current.x_613789_myprofile_career.reviewers.toString().indexOf(gs.getUserID()) > -1
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2023 11:40 PM - edited ‎02-22-2023 11:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2023 08:30 PM
you should not use the table name to get field value
use this
current.reviewers.toString().indexOf(gs.getUserID()) > -1
also update script as this and use callback with GlideRecord
function checkAttachment() {
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", g_form.getTableName());
att.addQuery('table_sys_id', g_form.getUniqueValue());
att.query(checkRecord);
function checkRecord(att){
if(!att.next()) {
alert("Please attach the screenshot of the certification verification.");
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2023 03:03 AM
Did you get a chance to check my above script?
you can enhance it further to check the file extensions
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader