Inline Scripting - Minus one record from another

StephenL1
Tera Contributor

Hi there,

I've created a "Consume Asset" flow in flow designer. It reads from a record producer where you say what consumable you will be checking out and how many of it.

 

I'm trying to update the consumable record so that it gets the current consumable quantity and takes away the number inputted from it to set the current quantity.

 

The problem is, when using an inline script it will not let me subtract one data pill from another.

What I would like to do:

 

 

var quantity = fd_data._6__look_up_record.record.quantity ;

var takeAway = fd_data._2__get_catalog_variables.how_many_of_this_item_are_being_deployed;

return quantity - takeAway;

 

But this errors out removes the code every time I try to save my flow.

I know that the logic is correct because if I do:

 

 

var takeAway = fd_data._2__get_catalog_variables.how_many_of_this_item_are_being_deployed;

return takeAway - 2;

 

 

or

 

 

var quantity = fd_data._6__look_up_record.record.quantity ;

return quantity -  3;

 

 

It will work fine. For some reason it just wont let me subtract the two variables form each other.

 

For context, quantity is an int and takeAway is a string.

 

Screenshot 2023-01-31 at 5.26.39 PM.png

 

Screenshot 2023-01-31 at 5.26.07 PM.png

 Any help here would be great!

5 REPLIES 5

Johns Marokky
Tera Guru

Hi @StephenL1 ,

Try the below script and see if its working. In the code I am trying to convert the takeaway to an Integer value. Try and see if it works for you.

var quantity = fd_data._6__look_up_record.record.quantity ;

var takeAway = fd_data._2__get_catalog_variables.how_many_of_this_item_are_being_deployed;

var takeAwayInt = parseInt(takeAway,10)

return quantity - takeAwayInt;

 

Mark Helpful if it helps in solving your query.

 

Regards,

Johns

Hi Johns,

Unfortunately this didn't seem to work either. Just seems to happen every time I reference a second data pill in a piece of code. I'd also tried converting to int a few different ways with ParseInt(), Number(), and +(). None of them worked.

newhand
Mega Sage

@StephenL1 

I have met the same issue。

Inline scripts was removed when saving the flow for unknow reason。

I tried many times and finally it was successful saved。。

But even now i still don't know why they are removed。

 

Maybe avoid using Inline scripts is a better way。

You can do the logic in a action,and set the action result to the field you want to fill。

 

 

 

Please mark my answer as correct and helpful based on Impact.

Hey,

Good to know it's not just me thats having an issue! 

 

When you say use logic in an action, could you specificy what you mean?

My thought was to basically get the inputted number and do a for each loop that would take away 1 quantity for each number that is in the inputted number. But the logic only allows for each to work with a list, not an int. So thats also a bit of a bust 😞 .