2021年4月22日星期四

Generate a random string on employee custom field in ERPNext

I have a custom employee field called Misconduct Case Number that's supposed to be extracted and used elsewhere outside ERPNext. The random string should be in the format [8 Alfanumeric charactors] [Date & Time] [Constant Organization Number] eg DX0FBN78 04200645 PTD0010045

For some reason, I am not able to generate the random string using the following custom script and there are no errors in the console.

frappe.ui.form.on('Employee', {      validate: function (frm) {          randString(frm);      }  });        var randString = function (frm) {      var s = "";      var x = "";      var today = new Date();      var date = String(today.getFullYear()).substring(2, 4) + '' + (today.getMonth() + 1);      var time = today.getHours() + "" + today.getMinutes();      var dateTime = date + time;      var compNumber = " STR18001749";      while (s.length < x && x > 0) {          var r = Math.random();          s += (r < 0.1 ? Math.floor(r * 100) : String.fromCharCode(Math.floor(r * 26) + (r > 0.5 ? 97 : 65)));      }        let  my_generated_string  = s.toUpperCase() + ' ' + dateTime + compNumber;      frm.doc.misconduct  =  your_generated_string ;      refresh_field('misconduct');  };  
https://stackoverflow.com/questions/67223407/generate-a-random-string-on-employee-custom-field-in-erpnext April 23, 2021 at 11:01AM

没有评论:

发表评论