[DEV] Changes of doctype not reflected in the browser

Hi guys,

I am changing document (instance) server-side and want this change to be reflected after

frappe.set_route(“Form”, “MyDoctype”, “MyDoctypeName”)

is called. For the moment when I change some of the values in the DB they are not updated in the view.
Should I call:

frm.reload_doc();

as a callback to set_route?

Cheers

1 Like

Nobody using set_route or reload_doc? :slight_smile:

For the moment

frm.reload_doc();

is not working I will try triggering refresh event or clicking reload in the menu. Actually I find this a very bad solution, I will highly appreciate any tips guys!

@Marcin_Walkow

call bench --site [sitename] clear-cache

If you change doctype properties from the front end, you don’t need to do that (thats the way it is supposed to be designed)

@rmehta - thank you for the reply.
I am talking about an instance, not a Doctype properties. Let say I am changing one of the ToDo tasks after Customer details update.

However after

doc.save()

The browser still gives me old values. :frowning:
One of the solutions is triggering click on Menu->Reload but I find this solution ugly and error prone.

frm.doc_reload ();

is not working from Save button callback.

It is still not very clear. Can you share the full code snippet?

@rmehta
Below please find snippets

Custom script for My Test Doctype

frappe.call({
		method:"my_test.my_test.my_test.doctype.my_test_doctype.my_test_doctype.create_next_doc",
		args: {
				curDoc: JSON.stringify(frm.doc)
		      },
                callback: function(response){
                                  nextDoc = response.messages.nextDoc
                                  nextDocName = response.messages.nextDocName
                                  error = response.messages.error
                                  if(error)
                                  {
                                            frappe.msgprint(error);
                                  }
                                  else if (nextDoc != null && nextDocName != null)
                                  {
                                             frappe.set_route("Form", nextDoc, nextDocName);
                                             //here I have tried to reload doc - by frm.doc_reload();
                                  }
                  }
       });

Server side logic

@frappe.whitelist()
def get_next_doc(curDoc):
    retDict = { }
    nextDoc = None
    error = None
    curDoc = json.loads(curDoc)
    curDocName = curDoc.get("name", None)
    activity = curDoc.get("activity", None)
    
    if curDocName == None:
        error = "error: name field not given"
    elif activity == None:
        error = "error: activity field not given"
    else:
        if activity == "Forward":
            nextDoc = "My Next Doctype"
        else:
            nextDoc = "My Previous Doctype"
        create_next_doc(nextDoc, curDocName, activity)
        retDict['curDocName'] = curDocName
        retDict['nextDoc'] = nextDoc
    retDict['error'] = error
    return retDict
def create_next_doc(doctype, curDocName, activity):
    doc = None
    if frappe.db.exists(doctype, curDocName):
        doc = frappe.get_doc(doctype, curDocName)
        doc.activity_status = activity
        doc.flags.ignore_mandatory = True
        doc.save()
    else:
        doc = frappe.get_doc({
            "doctype" : doctype,
            "doc_name" : curDocName,
            "activity_status" : activity
        })
        doc.flags.ignore_mandatory = True
        doc.insert()

The thing is that when I update My Test Doctype and move to Next or Previous Doctype the value is not udpated for activity_status.
It is updated in the DB because when I refresh via F5 or click on Reload in Menu it is getting proper values.
That’s why I have tried frm.doc_reload() or triggering click.

@rmehta

Not sure if this is relevant but I am getting this error on socket.io on my developer server:
CONNECTION REFUSED
http://my_domain:9000/socket.io/?EIO=3&transport=polling&t=1470305960435-121

UPDATE: Fixed above issue (not relevant).

Of course I am getting this when moved to next document:

Error: Document has been modified after you have opened it (2016-08-04 15:46:27.622740, 2016-08-04 15:46:44.403341). Please refresh to get the latest document.

Looks like when I insert or update document for 1st time in particular browser tab the frontend “knows” it has changed.
When in the SAME “seesion” (without reload / refresh) I change values in the backend I get this error.

I have seen many post and issues like this and ERPNext unable to awnser them and some time dont know what to say and some time they dont understand what we need. Are they realy professionals? is frappe realy done by people like? @rmehta
Many posts are disappointing.

1 Like

Use window.location.reload(); instant of frm.doc_reload may be it helps

1 Like

@mtajammul this is a free, volunteer-supported forum. The people answering here volunteer their time and energy for the good of the community.

If you are not happy with the completely free support people do their best to voluntarily provide, please take the step to pay for developer support with an SLA from a service provider. That’s the best advice I can give to help you achieve your goals.

I’m closing this thread for now. If more help is needed, please start another thread.

3 Likes