Ui action visibility and attachment check

sanjana5
Tera Contributor

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 

2 ACCEPTED SOLUTIONS

@sanjana5 

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
}

 

 

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

View solution in original post

@sanjana5 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

 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';
}

@sanjana5 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

BharathChintala
Mega Sage

@sanjana5 

 

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
}

 

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

@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.

 

@sanjana5 

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
}

 

 

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala