script

cancel
Showing results for 
Search instead for 
Did you mean: 
chavezdf
Member II

script

I have made a script to set the document type depending of word of their name.

if (document.parent.hasAspect("pp:freightFolder")) {
var file = document.name;
var dict = new Object();
document.addAspect('pp:document');
document.properties["pp:refBlNumber"] = document.parent.properties['pp:bl_number'];
document.properties["pp:refHblNumber"] = document.parent.name.slice(1);
document.properties["pp:refContainers"]=document.parent.properties['pp:containers'];

dict = {
"Proform Invoice":"PIN",
"PI":"Proform Invoice",
"PIN":"Proform Invoice",
"Invoice":"Invoice",
"INV":"Invoice",
"Packing List":"Packing List",
"PKL":"Packing List",
"PKG":"Packing List",
"Packing List Cropped":"Packing List Cropped",
"Cropped":"Packing List Cropped",
"PKC":"Packing List Cropped",
"Invoice & Packing List":"Invoice & Packing List",
"IPK":"Invoice & Packing List",
"Booking":"Booking",
"BKG":"Booking",
"ISF":"ISF",
"Arrival Notice":"Arrival Notice",
"ARN":"Arrival Notice",
"Freight Invoice":"Freight Invoice",
"FIN":"Freight Invoice",
"Bill of Lading":"Bill of Lading",
"BOL":"Bill of Lading",
"Telex Release":"Telex Release",
"TXR":"Telex Release",
"Release":"Telex Release",
"Custom Entry":"Custom Entry",
"Custom":"Custom Entry",
"Entry":"Custom Entry",
"All Docs":"All Docs",
"ALL":"All Docs"
};


for(var key in dict) {
      if (file.toLowerCase().search(key.toLowerCase()) != -1) {
         document.properties["pp:docType"] = dict[key];
         if (dict[key] == "Packing List" || dict[key] == "Packing List Cropped"){
            document.addAspect('ppSmiley TongueackingRefNumber');
         }
         if (dict[key] == "Invoice" || dict[key] == "Invoice & Packing List" || dict[key] == "Freight Invoice") {
            document.specializeType('pp:Invoice');
         }
   }
}
document.save();

}

As you can see, in this script I assign to some docs the type "invoice".

This Invoice type has a property called invoiceStatus with a DEFAULT VALUE: "Not Processed".

Ok, knowing this, here come the problem:

I also have a smart folder, with this query: "query": "=pp:invoice_status:'Not Processed' and =pp:docType:'Invoice'"

When I add a file with a string invoice inside its name, it change its name and assign the type invoice to the file, and i suppose the default value with it.

But when I go to the smart folder to check if the file is in it. It doesn't!!!!

I have to go to the file, open its properties (all properties are there) and just save the file (without modifying nothing). Then I can go to the smart folder and there it is!

It seems that when I assign a property to a document using a script it does not really assign the default value.

I made a second test:

I create a simple rule, where: if a document is create and its a type is "content", and the name begins with invoice, then assign specilizetype "invoice".

When I drag and drop a file with name begining with Invoice, the rule assigns it the typ invoice, and it assigns the default value pp:invoice_status:'Not Processed', and then when I go to the smart folder it appears.

My conclusion is that when we use a script, default values are not being assigned. Some one can confirm me that? Or there is a real problem here?

1 Reply
jpotts
Professional

Re: script

After you drop a doc into your folder to trigger the rule, and before you edit the document, have you gone into the node browser to inspect the value of pp:invoice_status? I think it might be instructive.