Problem with new script

Hi there,

I created a simple new script and it works w/o problems:

def totalGood = doc['actualQuantity'].value - doc['failureQuantity'].value; return totalGood;

Then I tried to create another one and this one does not work and I do not see why.

def goodinPercent = doc['totalGood'].value / doc['actualQuantity'].value; return goodinPercent;

Can you please help me out with this?

Thank you.

Valerija

Hey, you cant reference a scripted field in another. You need to change your second script. Sometihng like:

def totalGood = doc['actualQuantity'].value - doc['failureQuantity'].value; return totalGood;

def goodinPercent = totalGood/ doc['actualQuantity'].value; 



1 Like

Hello,

Thank you so much for quick reply. I was not aware of that rule - thank you.

Now I changed the script as you suggested but is still does not work.

def goodinPercent = 'totalGood' / doc['actualQuantity'].value;

Any idea what might be a problem? :frowning:

Thank you so much in advance.

Regards.
Valerija

I think my script has an error. Try to remove the return

def totalGood = doc['actualQuantity'].value - doc['failureQuantity'].value; 

def goodinPercent = totalGood/ doc['actualQuantity'].value; 
return goodinPercent;

I did the following and still does not work...I probably do not understand what I should do so I did printscreen for you to see.

type or paste code here

def totalGood = doc['actualQuantity'].value - doc['failureQuantity'].value;
def goodinPercent = 'totalGood'/ doc['actualQuantity'].value;
return goodinPercent;

Do you see any failures?

Yes, but it says that the script is invalid.

aaaa I think the problem is that you are adding "" on the variable

def goodinPercent = totalGood/ doc['actualQuantity'].value;

should be totalGood without the quotes

I tried...with and w/o and still no luck.... :frowning:

You have to check the preview to see the errors. Are the fields that you are subtracting of the same type?

Let me give you additonal info...

  1. I have created script and it works

  2. then I wanted to create another script that would do calculation with data from TotalGood and actualQuantity

so, what I thought is that since the first script is created and working, then I need to put in the second script just

def goodinPercent = totalGood / doc['actualQuantity'].value;

...but no luck with anything I did so far...

both are painless, if that is what you are referring to

What type is the totalGood and what type is the doc['actualQuantity']?

There is this Get help with the syntax...

If you click it you will see which is the problem

both are painless...

...I did check the link you mentioned but see no reasons for error....

Painless is the language not the type. Here you are creating a number scripted field but you need to check the type of the fields you are you using inside your script. Can you send a screenshot of the preview errors?

There is so much for me to learn! :smiley: thank you for having patience with me...

here is the preview of the error...
image

When you click the Get help with the syntax and preview the results of your script a flyout opens. I want a screenshot from the preview results tab

OK, I see...sorry...

Remove the quotes from totalGood and send me the screenshot again.