Friday, 29 November 2024

Set dispute flag for multiple invoice lines

Groovy script:


import com.sap.gateway.ip.core.customdev.util.Message;

import java.util.HashMap;


def Message processData(Message message) {

def body = message.getBody(java.lang.String);

def newbody = body.replace('-','_');

def list = new XmlSlurper().parseText(newbody);


def map = message.getProperties();

def InvoiceId = map.get("InvoiceId");

def disputeInvoice = "No";

def returnInvoiceError = "No";

int counter = 0;

def approval_id = list.invoice_header.approvals.approval.id.text();

def InvoiceType = list.invoice_header.invoice_lines.invoice_line[0].custom_fields.item_category.text();

def DocumentType = list.invoice_header.document_type.text();

def InvoiceNumber = list.invoice_header.invoice_number.text();

def AccountType = list.invoice_header.account_type.name.text();

int lengthofInvoiceNumber = InvoiceNumber.length();

message.setProperty("approval_id",approval_id);

list.invoice_header.invoice_lines.invoice_line.each

{

counter = counter + 1;

}

if((DocumentType == "Invoice") && (InvoiceType == "Services") && (AccountType.contains("GBL")))

{

if(counter > 1)

{

disputeInvoice = "Yes";

returnInvoiceError = "Invoice Id: " + InvoiceId + " " + "is a Service Invoice with multiple Invoice lines. Please submit new invoice with single line only and do not issue a credit memo."

}

}

message.setProperty("disputeInvoice",disputeInvoice);

message.setProperty("returnInvoiceError",returnInvoiceError);

return message;

}




No comments:

Post a Comment