Publié Fri, 04 Jan 2019 17:12:36 GMT par Casey Miller Director of Technical Services

Ok, I am very new to this. I am stuck at step 2 lol. When it is saying Clone the Sources : git clone https://github.com/DocuWare/Validation-NodeJS-samples.git how exactly do you do the clone?? I've tried command prompt and opening nodeJS and running this command but I get syntax error. It is just confusing because then in step 3 it says in command prompt navigate to the folder where the sample app was cloned... how do I know where it was cloned?

 

I am using this site for the instructions https://github.com/DocuWare/Validation-NodeJS-samples. Any help would be greatly appreciated. Essentially I want to be able to validate whether an invoice with matching invoice number doc type of invoice and vendor name is already in the cabinet. looks like they already have something like that feature for check for already existing invoices before storing.

EDIT: Ok so I have gotten all of the setup and configuration figured out. Just took some digging around and playing. I am getting a good connection but am receiving this error ? error is attached

 

 

https://www.docuware.com/sites/default/files/forums-images/validations_error.png

Publié Fri, 04 Jan 2019 21:25:45 GMT par Casey Miller Director of Technical Services

This was not a file that I have touched so I am not sure why I am getting this error. It actually specifically states not to touch this file. 

Publié Mon, 07 Jan 2019 18:10:17 GMT par Casey Miller Director of Technical Services

Anyone have any suggestion on this? It seems like a node_module didnt get installed or something..

Publié Thu, 10 Jan 2019 18:20:14 GMT par Casey Miller Director of Technical Services

UPDATE: So I was missing the exports.checkValues function. Once this was added everything worked great. Below is what the validation before storing file looks like: (Mind you, all this does is validate that an invoice with doc type of Invoice, Invoice Number, and Vendor Number arent already in the cabinet being stored into. If there is a match, it notifies and won't let then store. Works great for not even allowing duplicate invoices in the system)

const DWparameters = require('./DWValidationSettings');
const validator = require('validator');    
const unirest = require('unirest');

 

exports.checkValues = function (DWInputValues) {
    var invoiceNo = this.getFieldValue(DWInputValues.Values, DWparameters.fieldNameDOCNUMBER);
    var supplierID = this.getFieldValue(DWInputValues.Values, DWparameters.fieldNameSUPPLIER);    

    return new Promise((resolve, reject) => {
        this.isDuplicateInvoice(DWInputValues.FileCabinetGuid, invoiceNo, supplierID)
         .then(success => {
            if (!success) {
                throw new Error('There is already an invoice stored (#'+ invoiceNo +'SupplierID:' + supplierID + ')');
            }

            return success;
        })
    .then(success => resolve(true))
                                .catch(function (error){
                                                reject(error);
                                })    
    });
}

exports.getFieldValue = function (DWIndexFieldCollection, fieldName) {
    var field = DWIndexFieldCollection.find(x => x.FieldName == fieldName);
    if (field === undefined) {
        return;
    }

    return field.Item;
}

exports.isDuplicateInvoice = function (fileCabinetGUID, invoiceNo, supplierID) {
    return new Promise((resolve, reject) => {    
        var CookieJar = unirest.jar(true);

        //logon to DW PLATFORM and retrieve cookie;
        unirest.post(DWparameters.DWPlatformUrl + '/Account/Logon')
        .headers({'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded'})
        .jar(CookieJar)
        .send({ 'UserName': DWparameters.DWPlatformUser, 'Password': DWparameters.DWPlatfromPassword, 'Organization': DWparameters.DWPlatformOrganization, 'RememberMe': false, 'RedirectToMyselfInCaseOfError': true })
        .end(function (response) {
            unirest.post(DWparameters.DWPlatformUrl + '/FileCabinets/'+ fileCabinetGUID +'/Query/DialogExpression?dialogId='+ DWparameters.DWSearchDialogGUIDForInvoiceSearch +'&format=table')
            .headers({'Accept': 'application/json', 'Content-Type': 'application/json'})
            .jar(CookieJar)
            .send({ 'Condition':[
                { 'DBName':DWparameters.fieldNameDOCNUMBER, 'Value': [invoiceNo] },
                { 'DBName':DWparameters.fieldNameSUPPLIER, 'Value': [supplierID, null] },  
            ],
            'SortOrder':[],'ForceRefresh':true,'FlagConditions':{'IncludeCheckedOut':false},'Operation':'And','AdditionalResultFields':[],'Start':0,'Count':1})
            .end(function (response) {
                if (response.error) {
                    return reject(new Error(response.error.message));
                }

                try {
                    var resultCount = response.body.Count.Value;
                    return resolve(resultCount == 0);                
                } catch (error) {
                    return reject(new Error("Unable to retrieve similar invoices. Error:" + error));
                }
            });
        });
    })
}

You must be signed in to post in this forum.