Calculate probability

Hi all… I have added a server script where if my probabilty value is in between 0 to 30 the probabilty value will be low and like for medium(30 to 60)and high(60 to 90).

if doc.probability1 >= 0 and doc.probability1 <= 30:
doc.db_set(‘probability_value12’, ‘Low’)
if doc.probability1 > 30 and doc.probability1 <= 60:
doc.db_set(‘probability_value12’, ‘Medium’)
if doc.probability1 > 60 and doc.probability1 <= 100:
doc.db_set(‘probability_value12’, ‘High’)

but this error is coming

please help.
i have given data-type for both the fields as Data.
Thank you.

Hi @SonalD,

Please apply and check it.

if doc.probability1 >= 0 and doc.probability1 <= 30:
    doc.probability_value12 = "Low"
if doc.probability1 > 30 and doc.probability1 <= 60:
    doc.probability_value12 = "Medium"
if doc.probability1 > 60 and doc.probability1 <= 100:
    doc.probability_value12 = "High"

Please set your field name according.

Thank You!

Thank you…but still same error is coming.

share your error image

It’s worked on my side.


when we are filling the data before saving it…this error is coming.

is probability1 field type Int?

its data.

Thank you NCP. It is working when i change date type as int.

can i ask one more question?

Yes, Please.

How to get month from an existing date using client script
Example: date-1/11/2021
Output: 11/2021

i have one field inquiry date. from which i want to get his month in lead generation month field.

can we connect over telegram for better connecting?

basically my probability is in percentage.If i change my probabilty as datetype percent it not working…can you guide me over that how that will work

Hi @SonalD,

the scenario set in the opportunity.
Please check it script.

frappe.ui.form.on('Opportunity', {
	transaction_date: function(frm) {
	  //var curdate = your_date_field;
		var curdate = frm.doc.transaction_date;
        var dateObj = new Date(curdate);
        var month = dateObj.getUTCMonth() + 1;
        var day = dateObj.getUTCDate();
        var year = dateObj.getUTCFullYear();
        
        frm.set_value("your_field_name", month +"/"+ year);
    // output : 11/2022
    // field type must be data.
	}
});

Thank You!

1 Like

It’s worked on my side.

Thank You!