Highlighted

Run JavaScript From Action Wizard Instead Of Application Level File

Explorer ,
Jun 21, 2020

Copy link to clipboard

Copied

Hey all,

 

I've been using this code in a JavaScript file saved in the application folder and calling the function from the Action Wizard but I want to paste the code from the JavaScript file into Action Wizard so I can transfer the Action Sequence across multiple computers and not have to worry about the JavaScipt file as well. Any ideas on how I would change this so runs inside of the Action Wizard? Thanks 🙂

 

 

// Enter and validate 8 digit numeric case number and add to bookmarks
function enterCase() {
	if (this.bookmarkRoot==null || this.bookmarkRoot.children==null || this.bookmarkRoot.children.length==0) {
		app.alert("Error! There are no bookmarks in this file.",0,0,"COMPANY NAME");
		event.rc = false;
		return;
	}
	var resp = "";
	while (resp=="") {
		
		var dialog1 = {
			initialize: function (dialog) {
			},
			
			commit:function (dialog) {
				var results = dialog.store();
				resp = results["txt1"];
			},
			
			description: {
				name: "COMPANY NAME",
				align_children: "align_center",
				elements: [
				{
					type: "view",
					align_children: "align_left",
					elements: [
						{
							type: "static_text",
							name: "Enter case number:",
							bold: false,
							font: "dialog"
						},
						{
							item_id: "txt1",
							type: "edit_text",
							alignment: "align_fill",
							bold: true,
							font: "dialog"
						},
						{
							alignment: "align_right",
							type: "ok_cancel",
							ok_name: "OK",
							cancel_name: "Cancel",
							bold: false,
							font: "dialog"
						}
					]
				}]
			}
		}

		if (myTrustedExecDialog(dialog1)!="ok") {
			app.alert("Error! Enter case number cancelled by user.",0,0,"COMPANY NAME");
			event.rc = false;
			return;
		}
		if (/^\d{8}$/.test(resp)==false) {
			app.alert("Error! Invalid case number. Please try again.",0,0,"COMPANY NAME");
			resp = "";
		}
	}
	for (var i=0; i<this.bookmarkRoot.children.length; i++) {
		this.bookmarkRoot.children[i].name = resp + " " + this.bookmarkRoot.children[i].name;
	}
}

myExecDialog = app.trustPropagatorFunction(function(dialogName){
	app.beginPriv();
	return app.execDialog(dialogName);
	app.endPriv();
});

myTrustedExecDialog = app.trustedFunction(function(dialogName) {
	app.beginPriv();
	return myExecDialog(dialogName);
	app.endPriv();
});

 

 

 

 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You don't need to change anything, beside add a call to the function. You can also get rid of the trusted functions and replace them with regular calls, as an Action runs in a privileged context by definition.

However, if you use this code in an Action it will prompt you for each file you process, which kind of defeats the purpose of a batch process. The code (which I believe I wrote) can be modified to only prompt the user once and then use the same information for all files.

Topics

Acrobat SDK and JavaScript, Edit and convert PDFs, How to

Views

114

Likes

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

Run JavaScript From Action Wizard Instead Of Application Level File

Explorer ,
Jun 21, 2020

Copy link to clipboard

Copied

Hey all,

 

I've been using this code in a JavaScript file saved in the application folder and calling the function from the Action Wizard but I want to paste the code from the JavaScript file into Action Wizard so I can transfer the Action Sequence across multiple computers and not have to worry about the JavaScipt file as well. Any ideas on how I would change this so runs inside of the Action Wizard? Thanks 🙂

 

 

// Enter and validate 8 digit numeric case number and add to bookmarks
function enterCase() {
	if (this.bookmarkRoot==null || this.bookmarkRoot.children==null || this.bookmarkRoot.children.length==0) {
		app.alert("Error! There are no bookmarks in this file.",0,0,"COMPANY NAME");
		event.rc = false;
		return;
	}
	var resp = "";
	while (resp=="") {
		
		var dialog1 = {
			initialize: function (dialog) {
			},
			
			commit:function (dialog) {
				var results = dialog.store();
				resp = results["txt1"];
			},
			
			description: {
				name: "COMPANY NAME",
				align_children: "align_center",
				elements: [
				{
					type: "view",
					align_children: "align_left",
					elements: [
						{
							type: "static_text",
							name: "Enter case number:",
							bold: false,
							font: "dialog"
						},
						{
							item_id: "txt1",
							type: "edit_text",
							alignment: "align_fill",
							bold: true,
							font: "dialog"
						},
						{
							alignment: "align_right",
							type: "ok_cancel",
							ok_name: "OK",
							cancel_name: "Cancel",
							bold: false,
							font: "dialog"
						}
					]
				}]
			}
		}

		if (myTrustedExecDialog(dialog1)!="ok") {
			app.alert("Error! Enter case number cancelled by user.",0,0,"COMPANY NAME");
			event.rc = false;
			return;
		}
		if (/^\d{8}$/.test(resp)==false) {
			app.alert("Error! Invalid case number. Please try again.",0,0,"COMPANY NAME");
			resp = "";
		}
	}
	for (var i=0; i<this.bookmarkRoot.children.length; i++) {
		this.bookmarkRoot.children[i].name = resp + " " + this.bookmarkRoot.children[i].name;
	}
}

myExecDialog = app.trustPropagatorFunction(function(dialogName){
	app.beginPriv();
	return app.execDialog(dialogName);
	app.endPriv();
});

myTrustedExecDialog = app.trustedFunction(function(dialogName) {
	app.beginPriv();
	return myExecDialog(dialogName);
	app.endPriv();
});

 

 

 

 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You don't need to change anything, beside add a call to the function. You can also get rid of the trusted functions and replace them with regular calls, as an Action runs in a privileged context by definition.

However, if you use this code in an Action it will prompt you for each file you process, which kind of defeats the purpose of a batch process. The code (which I believe I wrote) can be modified to only prompt the user once and then use the same information for all files.

Topics

Acrobat SDK and JavaScript, Edit and convert PDFs, How to

Views

115

Likes

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
Adobe Community Professional ,
Jun 21, 2020

Copy link to clipboard

Copied

Paste the code there where you call the function.

Likes

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
Reply
Loading...
Most Valuable Participant ,
Jun 22, 2020

Copy link to clipboard

Copied

You don't need to change anything, beside add a call to the function. You can also get rid of the trusted functions and replace them with regular calls, as an Action runs in a privileged context by definition.

However, if you use this code in an Action it will prompt you for each file you process, which kind of defeats the purpose of a batch process. The code (which I believe I wrote) can be modified to only prompt the user once and then use the same information for all files.

Likes

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
Reply
Loading...
Explorer ,
Jun 22, 2020

Copy link to clipboard

Copied

Thanks Bernd and Try for your reply. You are correct Try this is your code from a few years back I actually emailed you for some rework but I didn't hear back and I really needed to get this sorted by today. I took both of your advice and I still cannot get it to run without error. Bernd I tried pasting the code as is it won't run. I also tried calling the function at the top of the code using enterCase(); and I keep getting "redeclaration of const" and "return not in function" errors. 

Likes

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
Reply
Loading...
Most Valuable Participant ,
Jun 22, 2020

Copy link to clipboard

Copied

I didn't see any email from you... Are you sure you used the right email address (try6767 at gmail.com)?

Try again, please.

Likes

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
Reply
Loading...
Explorer ,
Jun 22, 2020

Copy link to clipboard

Copied

Yup thats the one sent on Thursday of last week. I included a text file but I can't see that being an issue. I just forwarded it again.

Likes

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
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF