- 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-27-2023 11:03 PM - edited ‎02-27-2023 11:12 PM
when i click on the ui action it takes me to ui action script page insted of updating the state to completed. server side script. client is uncheked
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", g_form.x_613789_myprofile_career);
att.addQuery('table_sys_id', g_form.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';
}
- 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-23-2023 08:02 AM
Condition should be
current.reviewers.indexOf(gs.getUserID()) > -1
onclick should be empty
in script
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", "career");
att.addQuery('table_sys_id',current.sys_id);
att.query();
if (!att.next()) {
gs.addErrorMessage("Please attach the screenshot of the certification verification.");
current.setAbortAction(true);
}else
you have 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-27-2023 03:00 AM
@BharathChintala
the attachment type should be .png, .jpg or .jpeg if yes, it should set state to completed if not it should abort the action.
- 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