SanjivMeher
Mega Patron

Are you talking about special characters in attachment name?

Can you elaborate more about your use case?


Please mark this response as correct or helpful if it assisted you with your question.

Sarthak Kashyap
Mega Sage

Hi @D V Sandeep ,

 

I check for your problem in my PDI and it works for me, I checked for name in file name please check solution below 

 

I created a onChange client script on attachment variable and add below code

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    alert("Called = " + g_form.getValue('add_here'));

    var attachmentWidget = g_form.getControl('add_here');
    alert("attachmentWidget = " + JSON.stringify(attachmentWidget));
    var fileName = attachmentWidget.displayValue
    var invalidChars = /[%$@()&<>'"]/;

    if (invalidChars.test(fileName)) {
		alert("Your file name have invalid characters please remove and add");
		g_form.clearValue("add_here");
		return false;
	}

    }

SarthakKashyap_0-1764664387302.png

 

Result

 

My file has special characters

SarthakKashyap_1-1764664453279.png

 

SarthakKashyap_2-1764664467292.png

SarthakKashyap_3-1764664478111.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regard,

Sarthak

D V Sandeep
Tera Contributor

Hi @SanjivMeher 
When we try to attach a file to the attachment type variable in a record producer, the system should prevent the file from being attached if the file name contains special characters.

Hi @D V Sandeep ,

Did you check my solution ? I also did for file name only.

Hi @Sarthak Kashyap 
Thanks for your response. I checked your solution, but it is still not working for me. The system is still allowing files with special characters in the name to be attached. Please check the attached screenshot.
FYI, I have also used the variable attribute 'allowed_extensions=csv' for this attachment type variable.
Please check the below client script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    alert("Called = " + g_form.getValue('final_attachment'));

    var attachmentWidget = g_form.getControl('final_attachment');
    alert("attachmentWidget = " + JSON.stringify(attachmentWidget));
    var fileName = attachmentWidget.displayValue();
    var invalidChars = /[%$@()&<>'"]/;

    if (invalidChars.test(fileName)) {
        alert("Your file name have invalid characters please remove and add");
        g_form.clearValue("final_attachment");
        return false;
    }

}