All,I am having a little trouble calling a LS agent from a JS function. I am hoping someone can see what I may be doing incorrectly. I have 2 agents, and depending on whether the AttachmentDocID field is null or not I want to run one or the other agent.
I am getting the following error on the console when I run this:
HTTP Web Server: Couldn’t find design note [/SupplierPortal/LogisticsData.nsf/]
Here is my JSHeader code, which is called from a button using closingAgent():
function closingAgent() {
var servername;
var dbname;
var url;
servername=window.location.hostname
dbname = document.forms[0].DBName.value;
if (AttachmentDocID !== null) {
url = “http://” + servername + “/” + dbname + “/(Submit ULD wo Attachment)?OpenAgent”;
location.href = url;
}
else {
url = “http://” + servername + “/” + dbname + “/processAttachments?OpenAgent”;
location.href = url;
}
}
Thanks for any advice you can provide.
David
Subject: Calling LS Agent from JS
Where and how are you setting AttachmentDocID? Keep in mind that JS is expecting it to be a global variable in this code, and that !== means “is not identical to”, not “is not equal to” (which is !=). And are you returning false to the button onclick? If not, the form will submit.
Subject: RE: Calling LS Agent from JS
AttachmentDocID is set from an attachment submission popup.
The AttachmentDocID field is a computed field hidden with INPUT TYPE=HIDDEN NAME=“AttachmentDocID”>].
This may be the issue, that the code doesn’t see this field possibly?
My code for the onClick is:
var doc = document.forms[0];
validateFields();
doc.submit();
closingAgent()
Thanks
David
Subject: RE: Calling LS Agent from JS
You need to refer to the field through the reference chain, and since the field always exists, you have to query the value, not the field as such:
if (document.forms[0].AttachmentDocID.value != “”) {…}
An empty string is not the same thing as null.
Subject: RE: Calling LS Agent from JS
Stan,I changed my code to reflect…
if (AttachmentDocID.value !== “”) {
and when I run it, I get a page cannot be displayed and the following error on the server console:
04/14/2008 12:44:51 PM HTTP Web Server: Couldn’t find design note [/SupplierPortal/LogisticsData.nsf/]
Here again is my full function:
function closingAgent() {
var servername;
var dbname;
var url;
servername=window.location.hostname
dbname = document.forms[0].DBName.value;
if (AttachmentDocID.value !== “”) {
url = “http://” + servername + “/” + dbname + “/(Submit ULD wo Attachment)?OpenAgent”;
location.href = url;
}
else {
url = “http://” + servername + “/” + dbname + “/processAttachments?OpenAgent”;
location.href = url;
}
}
Any further thoughts?
David
Subject: RE: Calling LS Agent from JS
doc.submit(); <–closingAgent()
If you are submitting the doc, and then wanting an agent to run, shouldn’t you be using a webquerysave agent?
Subject: RE: Calling LS Agent from JS
I have it working in the webquerysave event, but I have multiple buttons on the form to which I do not want this agent firing on. That is why I need to have it run from the JS button.
Subject: RE: Calling LS Agent from JS
In the WebQuerySave event, you can do more that just call @Command([ToolsRunMacro]). You can e.g. add additional formula logic to decide, if the agent should be called.
Subject: RE: Calling LS Agent from JS
Yes I know you can do additional code in the WebQuerySave; however, I have several different save buttons on the form based on the user level. On one button I am wanting to run this save functionality with the agents; however, the other save buttons I do not.
Here is my WebQuerySave:
runAgent := @If(AttachmentDocID != “”; “processAttachments”; “SwoA”);
@Command([ToolsRunMacro]; runAgent)
Can you offer any suggestions on a coding methodology that the above will only run if 1 particular button is clicked?
Thanks
Subject: RE: Calling LS Agent from JS
Wow… workflow isn’t centralized in this app… is it?
First things first… Timothy is correct.
var doc = document.forms[0];
validateFields();
doc.submit(); <------- doing anything after a documents.forms[0].submit() is risky. One of your agents is not going to fire or one of your agents might not have a context doc.
closingAgent()
Two… the “Cannot Locate Design Note” is pretty explicit. It means it can’t find one of the agents you’re calling. I’ve had bad experiences with the parenthesis and aliases. Make sure you wrap the parenthesis around the left side agent name… then add the pipe… then the alias. No spaces.
Example: (Process Main Doc)|agtProcessMain
That might not be the cause of your problem but you’re basically either calling (by javascript URL or Toolsrunmacro) a bad agent name.
Subject: RE: Calling LS Agent from JS
You can have the button you click run a different web query save agent…
For example, define a field on the form (type=“hidden”) called AgentRunner.
Have your button set a value in it and then submit. Then use this for your web query save agent:
@If(AgentRunner = “”; @Return(“”); @Command([ToolsRunMacro]; AgentRunner))
Now you can have multiple post-agent code handle your different button clicks.
Subject: RE: Calling LS Agent from JS
Tim,This worked awesome. This is great for a non-JS coder.
I appreciate your help.
David