CORS Issue in frappe

I am having an issue using frappe.call in ERPNext v12. the error is down below.

The one in the right is the error and the one circled in green is the method being called in frappe.call(). Does anyone know how to resolve this?

Can you please provide the JavaScript and Python code here? We need to see the code to understand the issue because we’re not familiar with how to use it in frappe.call.

Hi @NCP ,

Here is the Javascript code.

frappe.listview_settings['Item'] = {
    refresh : function(listview) {
        listview.page.add_inner_button("Rename Item", function(){
            ButtonFunction(listview)
        })
    }
}

function ButtonFunction(listview) {
    frappe.call({
        method: 'tan_maufacturing_customizations.tan_maufacturing_customizations.renaming_item.rename_item',
        callback: function(r) {
            console.log(r.message);
        }
    });
}

And here is the Python code…

import frappe

@frappe.whitelist()
def rename_item():
    new_names = []
    items = frappe.db.get_list('Item', filters={'item_group': 'Dairy and Chilled' }, pluck='name')
    for index in range(len(items)):
        new_name = 'CHLD' + calculate_number_len(index + 1) + str(index + 1)
        # frappe.db.set_value('Item', items[index], 'name', new_name)
        new_names.append(new_name)
        return new_names
    

@frappe.whitelist()
def calculate_number_len(num):
    num_of_zero = 6
    series = num_of_zero - len(str(num))
    return "0" * series

Maybe it’s not possible to rename on listview in v12.

If you want to rename, then use form view script. otherwise check it.

https://frappeframework.com/docs/user/en/api/document#frappe-rename-doc

Thank You!

Hi I tried doing this in the Item form view but it still gives me the same error.

Hi @Rabie_Moses_Santill1,

We don’t know if the code structure is correct in version 12 as many functionalities have been updated in newer versions. And support for versions 13 or below has been discontinued.

For more information, please refer to the guidelines.

Thank You!

Oh ok. Thanks btw.