Javascript help

Explorer ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Good Afternoon,

I have created a form in Acroabt PRO DC, in it I have a field with 2 javascript in, the first one is to make sure that all the fields are filled  and the second one is to attach a document to the form.

What happens now is, if I didn´t filled all the fields, appears a pop up alert with the info of witch fields are missing but the problem is that the 2nd code will run anyway, even if the they filled the fields or not, what I need is that the 2nd code (attach document) run only when the fields are all filled.

 

TOPICS
Acrobat

Views

569

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Most Valuable Participant , Apr 23, 2021 Apr 23, 2021
Then use this code:   if (Ex2ValidFields()) { try { var annot = this.addAnnot({ page: 0, type: "FileAttachment", point: [500, 500], noView: true, author: "Attachment" }); annot.cAttachmentPath; var attachmentObj = annot.attachment; if (attachmentObj !== null) { app.alert("file successfully added: " + attachmentObj.name,3, 0, "Pedido de Investimento"); var l = this.getField("lst1"); l.insertItemAt(attachmentObj.name, 2); } } catch(e) { if (e.name == ...

Likes

translate

Translate

Translate
Most Valuable Participant ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Combine the JavaScript into one, and only run the attach part of it is applicable.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

And How can I do this? the codes are:

 

1rst one: 

try {
var annot = this.addAnnot({
page: 0,
type: "FileAttachment",
point: [500, 500],
noView: true,
author: "Attachment"
});
annot.cAttachmentPath;


var attachmentObj = annot.attachment;
if (attachmentObj !== null) {
app.alert("file successfully added: " + attachmentObj.name,3, 0, "Pedido de Investimento");
var l = this.getField("lst1");
l.insertItemAt(attachmentObj.name, 2);
}
}
catch(e) {
if (e.name == "NotAllowedError") {
// do nothing
}
}

 

and 2nd

 

javascript is call -» 

{
(Ex2ValidFields())
}

 

I have tried like to put first the 2nd code and after the 1rs one mas the document still run the attached document even with blank fields

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Ex2ValidFields is your code, it is a function somewhere in the document or user JavaScripts. You have to find it, understand it, and work with it to give a success/failure code to test.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

I know where my code is 🙂 is in my javascript document 

 

CintiaC_0-1619162732987.png

 

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

if you open the console, do you get any errors? Seems like you're missing a condition to handle that part.

 

Maybe you also need to re-verify where are  you trying to run the event from: is it a custom calculating script?  a mouse-up event button?  a custom keystroke script? a custom format script? a custom validating script?

 

As Test Screen Name mentioned, you have a function thatis called from one of those fields.

 

You need to elaborate a condition to do something or do nothing when fields are empty and when fields are filled in, and then call that function only when such condition(s) are met.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Hi, tx a lot for your reply, so... the 1rs code is in my javascript document:

CintiaC_0-1619162776423.png

and I have created a button with mouse up event and put 3 javascript code in it, the 1rs one calls my function "Ex2ValidFields" and allow to attach documents, am I doing wrong? there is a better way to do it?

 

 

CintiaC_1-1619162833629.png

 

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Does the function Ex2ValidFields return a value?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Hi, yes this code valid if all the fileds are filled and show a pop up message alert with the name of the fields that need to be filled

 

CintiaC_0-1619162653720.png

 

 

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Showing an alert is not the same as returning a value...

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

right..sorry, very low experience 

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

It will be easier to help you if we could see the full code, or the actual file itself...

I see you have a variable in this function called bRtn. I'm guessing this is what holds the return value.

If that's the case then you can use it like this:

 

if (Ex2ValidFields()) {

// put code to attach document to the file here

}

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

OK, file attach, the button is the one with the icon of attach: 

CintiaC_0-1619172163777.png

 

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Do you want all of the actions under that button to be dependent on the return value of Ex2ValidFields, or just the one that attaches a document to it?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

yes I need all of the actions under that Button

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Then use this code:

 

if (Ex2ValidFields()) {
	try {
		var annot = this.addAnnot({
			page: 0,
			type: "FileAttachment",
			point: [500, 500],
			noView: true,
			author: "Attachment"
		});
		annot.cAttachmentPath;
	 
	 
		var attachmentObj = annot.attachment;
		if (attachmentObj !== null) {
			app.alert("file successfully added: " + attachmentObj.name,3, 0, "Pedido de Investimento");
			var l = this.getField("lst1");
			l.insertItemAt(attachmentObj.name, 2);
		}
	}
	catch(e) {
		if (e.name == "NotAllowedError") {
			// do nothing
		}
	}
	
	this.getField("Validacaochefia-direcao").display = display.visible;
	this.getField("NOKDIRECAO").display = display.visible;
	this.getField("Direcao").display = display.visible;
	this.getField("ObsDIRECAO").display = display.visible;

	this.mailDoc({
		cTo: "marlene.marques@kirchhoff-automotive.com",
		cCc: "bernardo.brandao@kirchhoff-automotive.com",
		cSubject: "Pedido de Investimento - VALIDAÇÃO",
		cMsg: "Cara Marlene,\n\nEm anexo envio o Pedido de Investimento devidamente preenchido, por favor validar se a informação está conforme o exigido, para mais informações, disponha.\n\nObrigado." 
	});
	
}

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

it work perfectly! thanks a lot

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

Hi try 67, Regarding the below code, everything work perfectly but the action of sending the email doesn´t, it stop after attach the email, can you please help me?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

That's how it is supposed to work. The user has to send the email manually. Doing so automatically requires installing a script on the local machine of each user.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

So if I want to have a code that doesn´t allow the useres to attach files without filled out all the fields I cannot have in a automatic way the code to send the email, this is it?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

Unless you can install a script on their machines, no.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines