Unable to pass values from Feeder file in a request

HI,

From a feeder file i am taking values called product id, product type and weight. I am using these Values to add items to basket, Based on product type add to basket request gets changes. I added if condition in the script to differentiate the add to basket request. I am also setting the productid and produt type values in session, While running the script i am getting errors and add to basket request is not working. can someone please help me in resolving this issue?

Feeder file is in CSV format -

p_ProductId,p_maxWeightValue,p_productType
251627289,6.8,LooseQuantity

I am setting these values in session as -

.exec(session => {
var p_ProductId=session(“p_ProductId”).as[String]
var p_maxWeightValue=session(“p_maxWeightValue”).as[String]
val v_c_maxWeightValue=session(“p_maxWeightValue”).as[String]
var p_ProductType=session(“p_ProductType”).as[String]
session.set(“c_ProductId”,p_ProductId).set(“c_ProductForSale”,“true”).set(“productfound”,“0”).set(“c_maxWeightValue”,p_maxWeightValue).set(“p_ProductType”,p_ProductType)

})

If condition i am using these values -

if((v_c_maxWeightValue > 0) && (v_c_ProductType == “CatchWeight”)) {
var requestBodyAddToBasket="{“items”:[{“id”:""+v_c_ProductId+"",“newValue”:"+v_newValue+",“oldValue”:"+v_oldValue+",“newUnitChoice”:“pcs”,“oldUnitChoice”:“pcs”,“catchWeight”:"+v_c_maxWeightValue+"}],“loggedInAction”:“update-trolley-item”}"
session.set(“requestBodyAddToBasket”,requestBodyAddToBasket)

}else if ((v_c_maxWeightValue > 0) && (v_c_ProductType == “LooseQuantity”)) {
var requestBodyAddToBasket="{“items”:[{“id”:""+v_c_ProductId+"",“newValue”:"+v_newValue+",“oldValue”:"+v_oldValue+",“newUnitChoice”:“kg”,“oldUnitChoice”:“kg”}],“loggedInAction”:“update-trolley-item”}"
session.set(“requestBodyAddToBasket”,requestBodyAddToBasket)

}
else{
var requestBodyAddToBasket="{“items”:[{“id”:""+v_c_ProductId+"",“newValue”:"+v_newValue+",“oldValue”:"+v_oldValue+",“newUnitChoice”:“pcs”,“oldUnitChoice”:“pcs”}],“loggedInAction”:“update-trolley-item”}"
session.set(“requestBodyAddToBasket”,requestBodyAddToBasket)
}

Error i am facing while running the script -

12:46:58.651 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-31’ crashed with ‘j.u.NoSuchElementException: No attribute named ‘p_ProductType’ is defined’, forwarding to the next one
12:46:58.657 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-14’ crashed with ‘j.u.NoSuchElementException: No attribute named ‘c_ProductId’ is defined’, forwarding to the next one

Thanks in advance

I think there are a couple of issues here.

The session function does not have a return value. You must return the session object when you exit the function.

I have not compiled this, but it should look something like this:

.exec(session => {
var p_ProductId=session(“p_ProductId”).as[String]
var p_maxWeightValue=session(“p_maxWeightValue”).as[String]
val v_c_maxWeightValue=session(“p_maxWeightValue”).as[String]
var p_ProductType=session(“p_ProductType”).as[String]
session
}.set(“c_ProductId”,p_ProductId).set(“c_ProductForSale”,“true”).set(“productfound”,“0”).set(“c_maxWeightValue”,p_maxWeightValue).set(“p_ProductType”,p_ProductType)
)