Skip to main content
CintiaC
Known Participant
April 22, 2021
Answered

Javascript help

  • April 22, 2021
  • 2 replies
  • 3968 views

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.

 

This topic has been closed for replies.
Correct answer try67

yes I need all of the actions under that Button


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." 
	});
	
}

2 replies

Participating Frequently
April 1, 2022

Can anyone help me with this script?

\\ TAMPLATE FILL IMAGE //
1) Select the layer
2) Selected layer name change
3) Select multiple image Drive path
4) Open image >Copy>Close>First Select layer>Paste>Convert smart Object>Create clpping mask> fit to frame>Select layer name change

**Similarly selected layers will be filled

Brainiac
April 1, 2022

SUBIR23858377qxke, that's not really a script, it's a request for someone to write one for you. I have to say, it doesn't sound like anything that can be done in Acrobat JavaScript. I wonder if you really wanted a different forum?

Participating Frequently
April 1, 2022

I want a script just like the one I wanted

Brainiac
April 22, 2021

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

CintiaC
CintiaCAuthor
Known Participant
April 22, 2021

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

Bernd Alheit
Adobe Expert
April 22, 2021

Does the function Ex2ValidFields return a value?