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

Ankur Bawiskar
Tera Patron
Tera Patron

@sanjana5 

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

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

sanjana5
Tera Contributor

Hi @Ankur Bawiskar 

sanjana5_0-1677137964326.pngsanjana5_1-1677137985413.png

And the code for attachement check is also not working

sanjana5_2-1677138095569.png

field name is corect

@sanjana5 

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.

 

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

@sanjana5 

Did you get a chance to check my above script?

you can enhance it further to check the file extensions

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