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

Javascript help

Explorer ,
Apr 22, 2021 Apr 22, 2021

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.

 

3.4K
Translate
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
1 ACCEPTED SOLUTION
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 == "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." 
	});
	
}

View solution in original post

Translate
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

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

Translate
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

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

Translate
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

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.

Translate
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

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

 

CintiaC_0-1619162732987.pngexpand image

 

Translate
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

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.

Translate
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

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

CintiaC_0-1619162776423.pngexpand image

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.pngexpand image

 

Translate
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

Does the function Ex2ValidFields return a value?

Translate
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

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.pngexpand image

 

 

Translate
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

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

Translate
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

right..sorry, very low experience 

Translate
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

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

}

Translate
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

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

CintiaC_0-1619172163777.pngexpand image

 

Translate
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

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?

Translate
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

yes I need all of the actions under that Button

Translate
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

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

Translate
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

it work perfectly! thanks a lot

Translate
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

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?

Translate
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

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.

Translate
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

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?

Translate
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

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

Translate
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

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

Translate
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

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?

Translate
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

I want a script just like the one I wanted

Translate
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
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)?

Translate
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