Community

Setting a document field from a document processing script on a custom stage

Hi Everyone,

I'm trying to set a field on a document to the content of a registration parameter by calling a document processing script on a script workflow stage.

My workflow looks like as per Capture1 and Capture2 attached.

My code is as such

string propertyName = "fc_Predefined:InvoicePredefinedVendorId";
string vendorID = Document.Properties.Get(propertyName);
string supplierName = "";

if (vendorID == "1023")
{
supplierName = "AVIS";
}
else if (vendorID == "1334")
{
supplierName = "HERTZ";
}

if (Document.Field("Vendor\\VendorId").Text == "")
{
Document.Field("Vendor\\VendorId").Text = vendorID;
Document.Field("Vendor\\Name").Text = supplierName;
}

vendorID = "";
supplierName = "";
Document.Field("SupplierRegID").Text = "Test";


I'm testing the code in this section:

Document.Field("SupplierRegID").Text = "Test";


just to see whether I can unconditionally write something back into a field on the document. Nothing is written.

I suspect the paths to my fields might be at fault. See Capture3 attached for an overview of the document structure.

Should I be able to work in this way and if so what am I missing?

Many thanks

Richard

Was this article helpful?

0 out of 0 found this helpful

Comments

2 comments

  • Avatar
    Permanently deleted user
    Hello,

    What you are trying to do is generally done via script rules and not workflow.

    string vendorID = Context.Document.Properties.Get("%name%");
    string supplierName="";
    if (vendorID=="x")
    {
    supplierName="y";
    }
    else if (...)
    {
    ... //similar to previous if
    }
    //if using script rules and aliases there is no need to specify any extra subpath
    if (Document.Field("VendorId").Text == "")
    {
    Document.Field("VendorId").Text = vendorID;
    Document.Field("Name").Text = supplierName;
    }
    Document.Field("SupplierRegID").Text = "Test"; //can be added for testing as well.

    But before that please make sure your field Alias fit references that are made in code and Read-only checkmarks are set up accordingly.

    Hope that helps, Vladislav
    0
  • Avatar
    Permanently deleted user
    Thanks Vladislav, had tried a script rule but couldn't get the registration parameter to return correctly, your code helped me, all working!
    0

Please sign in to leave a comment.