How To set cost center branch wise in sales order using custom script

@moe01325 sir, I mapped branch cost centers with particular users but while making sales order it doesn’t came default in the field…how cam i make it possible…please help me with custom script to set cost centerCapture3

May I share two techniques in debugger javascript (You have to open the developer tools on the browser).

First, you may place “debugger”

frappe.ui.form....
   debugger
   $.each(frm.doc...

You may hit refresh on the browser. In the source pane of the Developers Tool, you will see the source code and when it hits debugger, you may step over (or into) to code. You may also place watch variables.

Another way is, (and they say this is a mark of a true javascript developer), place console.log(…) in your code. You can check the Console pane to see the values.

frappe.ui.... {
   console.log(frm, cdt, cdn)
  $.each .... {
      console.log(company)

Sometimes, you may be surprised at the values you did in your code. Debugging also gives you an appreciation of what the Frappe team did for us.

I hope I shared my fishing tips. Instead of giving fish.

1 Like

@shivansh13
did you try to place debug messages and see when they are triggered?
verified that that “validate” is correct?
verified that the if statement is correct to you usecase?

sir, I am new In erpnext so i couldn’t get what i tried for