Show Mandatory Attachment Field Conditionally in Record Producer Based on Catalog Variable Selection

VarshiniG
Tera Contributor

I have configured Mandatory Attachment in the Portal Settings of a Record Producer, which currently makes attachments mandatory for the entire record producer.

My requirement is to make the attachment mandatory only when a specific catalog variable option is selected (for example, when option A is selected). If another option (option B) is selected, the attachment field should be hidden and not mandatory.

Is there a way to control the visibility and mandatory behavior of attachments in a Record Producer dynamically based on a catalog variable choice selection?

Any guidance or best practice would be appreciated.

3 REPLIES 3

Tanushree Maiti
Kilo Patron

Hi @VarshiniG 

 

1. Remove Mandatory Attachment setting from your record producer

 

  • Open your Record Producer.
  • Go to Portal Settings.
  • Uncheck Mandatory Attachment

Sample screen shot

TanushreeMaiti_0-1777878586736.png

 

2 . Add an Attachment Variable:

  • In the Variables related list, click New.
  • Select Type: Attachment.
  • Label it ( like Please attach necessary documents).
  • Save it

3. Create a Catalog UI Policy:

In the Catalog UI Policies related list, click New.

    • Set Conditions: selected variable value is OptionA
    • Save the Policy.
  • Create UI Policy Actions:
    • In the Catalog UI Policy Actions related list, click New.
    • Variable Name: Select the attachment variable you created
    • Mandatory: True.
    • Visible: True.
    • Update.

4. Create a second policy where  selected variable value is OptionB

  • Set the attachment variable UI policy action to Mandatory: False and Visible: False.

 

You can try with OnSubmit Catalog client script as well.

 

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Hi @Tanushree Maiti ,
Thank you for your response.
I have already implemented the suggested solution, and it is working as expected. However, the client’s expectation is to leverage the “Mandatory Attachment” configuration available directly in the Record Producer’s portal settings, rather than controlling this behavior through variable-based (which aligns with the solution already implemented).

Could you please let us know if there is any supported approach to conditionally enforce the Mandatory Attachment setting from the portal configuration itself?

Regards,
Varshini 

Hi @VarshiniG ,

 

If Attachment variable related solution is not accpted, last option to 

Create a onSubmit client script

 

Sample code:

function onSubmit() {
    var sysIDrecord = g_form.getUniqueValue();
    var validateAttach = new GlideRecord('sys_attachment');
    validateAttach.addQuery('table_name', 'sc_cat_item_producer'); 
    validateAttach.addQuery('table_sys_id', sysIDrecord);
    validateAttach.query();
    if (!validateAttach.next()) {
        if (confirm('Please attach a document')) {
            return false;
        }
        else {
            return true;
        }
    }
}
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: