- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2022 01:46 AM
On Incident form there is a choice type (value-A, value-B)
If user selects the value- A, then attachment should be mandatory.
Please guide with the approach.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2022 08:35 AM
Hi @Srinivas K
You can use below logic in before insert or update BR:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var grA = new GlideRecord("sys_attachment");
grA.addQuery("sys_id", current.u_file_attachment_1); //replace with your attachment field name
grA.query();
if (grA.next()) {
if (grA.getValue("file_name").indexOf("doc") == -1) {
current.setAbortAction(true);
gs.addErrorMessage("Please enter the correct document name");
}
}
})(current, previous);
(=tested)
Hope it helps:)
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2022 01:51 AM
Hi @Srinivas K
You can watch the below video for making an attachment mandatory in native UI level.
https://www.youtube.com/watch?v=mBCuGw2GhpE&t=436s
Hope it helps to resolve your query.
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2022 04:16 AM - edited ‎11-10-2022 04:43 AM
Hi Murthy Ch,
My requirement is little bit different.
I am having a field (Ex: Document) with type - File attachment on the form.
When choice A is selected I am able to make the Document field mandatory.
But I also want to check whether the attached document contains particular word 'doc' in it.
If it is not there, then it has to abort , else it has to proceed.
How can I achieve it.
I am able to achieve this for the global attachment (on the top) , but not in the custom field that I have created.
(function executeRule(current, previous /*null when async*/) {
if (current.operation() == "update") {
checkUpdate();
}
function checkUpdate()
{
if(!gs.nil(current.sys_id))
{
var grAttach = new GlideRecord('sys_attachment');
grAttach.addQuery('table_name', current.getTableName());
grAttach.addQuery('table_sys_id', current.sys_id);
grAttach.addQuery("file_name",'CONTAINS','doc');
grAttach.query();
if (!grAttach.next()) {
gs.addErrorMessage('Missing Document attachment'); // Message to be displayed to user
}
current.setAbortAction(true);
}}
})(current, previous);
Please guide here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2022 08:35 AM
Hi @Srinivas K
You can use below logic in before insert or update BR:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var grA = new GlideRecord("sys_attachment");
grA.addQuery("sys_id", current.u_file_attachment_1); //replace with your attachment field name
grA.query();
if (grA.next()) {
if (grA.getValue("file_name").indexOf("doc") == -1) {
current.setAbortAction(true);
gs.addErrorMessage("Please enter the correct document name");
}
}
})(current, previous);
(=tested)
Hope it helps:)
Murthy