• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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.

 

Views

3.0K

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

Community Expert , 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 == 
...

Votes

Translate

Translate
LEGEND ,
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.

Votes

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

Votes

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
LEGEND ,
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.

Votes

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

 

Votes

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
Community Expert ,
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.

Votes

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

 

Votes

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
Community Expert ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Does the function Ex2ValidFields return a value?

Votes

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

 

 

Votes

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
Community Expert ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

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

Votes

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 

Votes

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
Community Expert ,
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

}

Votes

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

 

Votes

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
Community Expert ,
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?

Votes

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

Votes

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

Votes

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

Votes

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?

Votes

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
Community Expert ,
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.

Votes

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?

Votes

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
Community Expert ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

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

Votes

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
New Here ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

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

Votes

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
LEGEND ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

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?

Votes

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
New Here ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

I want a script just like the one I wanted

Votes

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
LEGEND ,
Apr 01, 2022 Apr 01, 2022

Copy link to clipboard

Copied

LATEST

Ok, SUBIR23858377qxke, exactly what Adobe application do you need the script for?

And exactly what version of the Adobe application (not "latest" please, but the actual numbers)?

Votes

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