Trigger and "getCgiVariable() called without an EJWebApp instance"

Continuing testing a solution for a customer and am trying to understand (finding an explanation on the community and the documentation was not successful) to the following error message:

I have the following script in the trigger "Sales: Before saving quote":

#setLanguageLevel 3;

Integer saleId = getCgiVariable("sale_id").toInteger();
Integer qId = getCgiVariable("quote_id").toInteger();

NSSaleAgent saleAgent;
NSSale sale = saleAgent.GetSale(qId);

NSQuoteAgent quoteAgent;
NSQuote quote = quoteAgent.GetQuote(qId);
quote.SetOrderComment(sale.GetDescription());
quoteAgent.SaveQuote(quote);

What am I doing wrong?

RE: Trigger and "getCgiVariable() called without an EJWebApp instance"

Hi Patrik,

In a trigger event handler, you should be pulling the SaleEntity from EventData...

Hope this helps.

 

Af: Tony Yates 6. okt 2020

RE: Trigger and "getCgiVariable() called without an EJWebApp instance"

Hmm, tried that. Will try again!

Af: Patrik Larsson 6. okt 2020

RE: Trigger and "getCgiVariable() called without an EJWebApp instance"

Tried using EventData but are getting this error then:

Using this code:

#setLanguageLevel 3;

EventData ed = getEventData();
Integer saleId = ed.getInputValue("SaleEntity.SaleId").toInteger();

NSSaleAgent saleAgent;
NSSaleEntity saleEntity = saleAgent.GetSaleEntity(saleId);
NSSale sale = saleAgent.GetSale(saleId);

NSQuoteAgent quoteAgent;
NSQuote quote = quoteAgent.GetQuoteFromSaleId(saleId);
quote.SetOrderComment(sale.GetDescription());
quoteAgent.SaveQuote(quote);
Af: Patrik Larsson 6. okt 2020

RE: Trigger and "getCgiVariable() called without an EJWebApp instance"

Hi Patrik,

You do not save a quote in a Before Save Quote event... It's already about to be saved. You just have to update it's values and let it go...

See this post for examples.

Also, make sure you are actually working with a SaleEntity..vs..QuoteEntity.

Af: Tony Yates 6. okt 2020