Community

Script to check if the reference value of the Vendor/ Tax ID was changed by the user

Hello everyone, i am an awful coder and new to scripting and today i would really appreciate some help, i would like to raise an error message in the following case when working with invoice documents : 

Les say i have an Invoice with a Vendor Tax ID wich is 123, if an user changes the vendor manually in manual document review the value of the the field Vendor/Tax ID will be replaced by the Vendor Tax ID  from the catalog. I would like to compare the value on the document with the value from the catalog if it is possible and raise an error message if they are different. I tried to do it with variables i save the value of the Vendor Tax ID in a variable but every time i change the vendor my variable is updated and i cannot compare the value in the document with the value in the catalog cause they are always the same made some images if it is confusing the goal of this to make sure that the user knows that the value located on the image is different to the value in the field.

Was this article helpful?

0 out of 0 found this helpful

Comments

7 comments

  • Avatar
    Tatiana Dyu

    Hi Viktor,

    I tried to do it with variables i save the value of the Vendor Tax ID in a variable but every time i change the vendor my variable is updated and i cannot compare the value in the document

    Maybe you can add an IF condition to your script to copy the value of the field only if the variable is empty, so it should populate it only once. Does it make sense to you?

    0
  • Avatar
    Adrian Enders

    What about making them 2 different fields? And simply compare the 2 fields.

    0
  • Avatar
    Viktor Stamenov

    Ok i am lost il will try to do it step by step in order to make this more simple. 

    I create a field called RefVendorTaxID (the idea is to use this field and save the value of the Vendor VATID the first time the document is processes) : 

    Now this is the the script can someone confirm that it is declared correctly, the problem with this script is that there is absolutely no control if the field is empty or not and if i choose the vendor manually from the catalog the value in the reference field will be updated :

     

    So i guess the next step is create a line and check if the RefVendorTaxID is empty if it is empty we execute the line of code from the screen, if it is not empty we do nothing because we have the information ? 

    0
  • Avatar
    Tatiana Dyu

    Hi Viktor,

    Correct. You can check the emptiness like this:

    if (Context.GetField("RefVendorTaxID").Text == "")
    {
      Context.GetField("RefVendorTaxID").Value = Context.GetField("Vendor/Tax ID").Value;
    }
    0
  • Avatar
    Viktor Stamenov

    Thanks for the response Tatiana, i did something similar, i think i will not raise an error an simplify the script because when i change the vendor it raises the error so i decided just to save the vendor VAT Id in the reference field. This is my script : 

    if (!Context.GetField("RefVendorTaxID").Value) {
      Context.GetField("RefVendorTaxID").Value = Context.GetField("Vendor/Tax ID").Value;
      Context.CheckSucceeded = true;
    }
    else {
      Context.CheckSucceeded = false;
    Context.ErrorMessage = 'Vendor Tax ID was updated by the user';
    }

    It works fine, but i have some trouble to output the content of RefVendorTaxID field after the text Vendor Tax ID was updated by the user i tried 

    Context.ErrorMessage = 'Vendor Tax ID was updated' + Context.GetField("RefVendorTaxID").Value;

    and i get : : Failed to parse the script. Exception: Line 8: Unexpected end of input

    Another question, is it possible to compare the RefVendorTaxID value with the value of the Vendor TaxId of the vendor from the catalog in the document (i guess i will have to work with the ID of the catalog record to get the value, compare the content of the fields : 

    0
  • Avatar
    Tatiana Dyu

    Hi Viktor,

     is it possible to compare the RefVendorTaxID value with the value of the Vendor TaxId of the vendor from the catalog in the document (i guess i will have to work with the ID of the catalog record to get the value, compare the content of the fields

    You are right. You can get the values from the script rule using a method GetCatalogRecord(string catalogId, string externalId) if you know the record id.

    As for the error message, I am not able to reproduce it on my end, so I have created a ticket, and the Customer Support Team will reach out to you shortly to investigate it further.

    0
  • Avatar
    Viktor Stamenov

    Hello i will be trying this next, thanks to the ABBYY support the error was fixed the problem was that i renamed the field on the document skill but i forgot to rename it in the script... this is the final result : 

    if (!Context.GetField("RefVendorTaxID").Value) { 
      Context.GetField("RefVendorTaxID").Value = Context.GetField("Vendor/Tax ID").Value; 
      Context.CheckSucceeded = true; 


    else { 
      Context.CheckSucceeded = false; 
      Context.ErrorMessage = 'Vendor Tax ID was updated' + ' ' + Context.GetField("RefVendorTaxID").Value; 
    }
    0

Please sign in to leave a comment.