Attachment to Form issue

Mohan Mallapu
Kilo Sage

Hi All/ @Ankur Bawiskar ,

I have created one custom form which will have some fields eg : 'Category' and 'Sub-Category' and 'custom attachment field' as per the requirement not used the attach icon. and Created one On-Change Client script(When category becomes 'software' need make the sub category field read-only and auto fill with some value) ------> Until here it is working as expected.

After selecting the category , While trying to add an attachment using custom attachment field it was redirected to another page to choose the file and routed back to the existing form after added the file.

But in the form the sub-category value is getting cleared. We don't have anything to clear this sub category field.


Kindly help me why this read only field is getting cleared???
Thanks in advance,,,,

8 REPLIES 8

@Mohan Mallapu 

is this happening for new record or existing record?

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

@Ankur Bawiskar  For both new and existing records , it is behaving same.

Hi Ankur,

 

Is there any way we can avoid the auto-save when we click the OOB file attachment button? Solutions like open in a new tab or abort the update.

 

Thank you

Harihara Sudhan M S

Anish Reghu
Kilo Sage
Kilo Sage

@Mohan Mallapu 

It is likely that the value of the sub-category field is being cleared because the onChange client script is being triggered again when you navigate back to the form after adding the attachment. This could be happening because the form is being refreshed or because the field is being modified in some way that causes the onChange script to run again.

One way to fix this issue would be to add a check in the onChange script to ensure that the sub-category field is only made read-only and auto-filled with a value if the category field is set to 'software'. You could do this by adding an if statement at the beginning of the script that checks the value of the category field.

For example:

if (g_form.getValue('category') == 'software') { // make sub-category field read-only and auto-fill with a value }

This way, the onChange script will only run if the category field is set to 'software', and the sub-category field will not be modified if the category field is set to a different value.

Alternatively, you could try using a different type of client script, such as an onLoad script, that runs when the form is first loaded and sets the sub-category field to read-only and auto-fills it with a value if the category field is set to 'software'. This would ensure that the field is not modified when the form is refreshed or when other fields are modified.

Kindly mark the response as Correct or Helpful.

Cheers,

Anish