Call to method using API server script

Hi

I have created a client script that calls a method in an api.py file in a custom-app.
its working. Here is the outline of how I am calling the method.

@frappe.whitelist()
def get_last_sequence_number(rack_id):

    //..... all code here : database select query
    
    if result and result[0][0] is not None:
        return result[0][0]
    else:
        return 0  



    frappe.call({
        method: 'custom_app.api.get_last_sequence_number',  
        args: {
            rack_id: rackId
        },
        callback: function(r) {
            if (r.message !== undefined) {

			//......code here

            } else {
                frappe.msgprint(__('Error: Unable to fetch last number.'));
            }
        }
    });
    

I want to change this so that I call the method where my python code is now in
a server-script ( type API ) and not in a custom-app.

I have changed it and it seems to work. I created a server script.
Type : API. Method : get_last_sequence_number. Here is my new outline …


    frappe.call({
        method: 'get_last_sequence_number',      
        args: {
            rack_id: rackId
        },
        callback: function(r) {
            debugger;
            if (r.lastNumber !== undefined) {

			//.....code here 

            } else {
                frappe.msgprint(__('Error: Unable to fetch last number.'));
            }
        }
    });
    
    

rack_id = frappe.form_dict.get('rack_id')

	//.....code here : database select query

if result and result[0][0] is not None:
    frappe.response["lastNumber"] = result[0][0]
else:
    frappe.response["lastNumber"] = 0 
    
    

My question :
Initially I still had

if (r.message.lastNumber !== undefined )......

but using the debugger it seemed that I have to change it to

if (r.lastNumber !== undefined) {

and it is working. It just took me by surprise as I was still expecting to use r. message.

So, even though it seems to be working, I thought it good to ask if this is
correct ?