Adding new menu entry from Javascript

I'm trying to update a menu from javascript, my scripts works but i can't see the the new menu entry, even when the record was saved in the table.

 

var file = new SCFile("MENU");
var query = file.doSelect("name=\"ESS MAIN\"");
var go=true;

if(query == RC_SUCCESS){

for (var y=0; y < (file.option.length()-1); y  ){

if (file.description[y]==system.vars.$name) {

print("Already exist " file.description[y]);
go=false;
	}
}

if (go==true){

file.option.push(file.option.length());
file.description.push(system.vars.$name);
file.application.push("menu.manager");
file.pname.push("name");
file.pvalue.push(system.vars.$name);
file.condition.push("true");

print( "Saving changes..." );

//rc=file.doUpdate();
//rc=file.doAction("update");
//rc=file.doSave();

rc=file.doAction("save");
print( 'doAction("save"): '   RCtoString(rc));

		}
	}
}

 

Parents
  • After making a change to the menu, the user has to reload the menu - either by logging out and logging back in or refreshing the menu itself.

    The displayed menu at any given time is a local copy of what is stored in the database; it's not a live look that changes dynamically and automatically as the record changes.  The user has to perform the action to tell the system to go get the updated copy.

Reply
  • After making a change to the menu, the user has to reload the menu - either by logging out and logging back in or refreshing the menu itself.

    The displayed menu at any given time is a local copy of what is stored in the database; it's not a live look that changes dynamically and automatically as the record changes.  The user has to perform the action to tell the system to go get the updated copy.

Children
  • I already try to refresh, logging out and logging back. i search the menu (in menu.g form) i see the new entry, only when i press the save button, the new entry Appears.

  • Verified Answer

    Hmm... I don't have the exact same code as you, so I can't validate, but I threw something similar in a javascript 

    function updateMenu(name){
    	var menu = new SCFile("menu")
    	var getMenu = menu.doSelect("name=\"" name "\"")
    	
    	if (getMenu == RC_SUCCESS){
    		menu.description.push("This is a test")
    		
    		menu.application.push("database")
    		menu.command[system.functions.lng(menu.description) -1]="pete"
    		menu.pname.push("name")
    		menu.pvalue.push("probsummary")
    		menu.condition.push("true")
    		
    		rc = menu.doAction("save")
    	}
    }
    updateMenu("ADMIN")

    and once I refresh the menu after running the script, the command works as expected and the item displays on the menu navigator.

    So, that may mean that, for your script, the way you're constructing one of the fields isn't quite correct, and the system is doing a built-in kind of autocorrect after saving.

    So, I'd recommend using the RAD Debugger.  Go to the menu you're updating and, in the debugger, check the contents of the $L.file variable.  Then, after saving the record, check the contents of the $L.file variable again.  Is something changing?  Like is the tool automatically adding quotation marks around anything, or performing some kind of code quality check - you know, like how it might put your parenthesis in different places or slightly change an expression... 

  • Verified Answer

    Hmm... I don't have the exact same code as you, so I can't validate, but I threw something similar in a javascript 

    function updateMenu(name){
    	var menu = new SCFile("menu")
    	var getMenu = menu.doSelect("name=\"" name "\"")
    	
    	if (getMenu == RC_SUCCESS){
    		menu.description.push("This is a test")
    		
    		menu.application.push("database")
    		menu.command[system.functions.lng(menu.description) -1]="pete"
    		menu.pname.push("name")
    		menu.pvalue.push("probsummary")
    		menu.condition.push("true")
    		
    		rc = menu.doAction("save")
    	}
    }
    updateMenu("ADMIN")

    and once I refresh the menu after running the script, the command works as expected and the item displays on the menu navigator.

    So, that may mean that, for your script, the way you're constructing one of the fields isn't quite correct, and the system is doing a built-in kind of autocorrect after saving.

    So, I'd recommend using the RAD Debugger.  Go to the menu you're updating and, in the debugger, check the contents of the $L.file variable.  Then, after saving the record, check the contents of the $L.file variable again.  Is something changing?  Like is the tool automatically adding quotation marks around anything, or performing some kind of code quality check - you know, like how it might put your parenthesis in different places or slightly change an expression... 

  • Verified Answer

    Hmm... I don't have the exact same code as you, so I can't validate, but I threw something similar in a javascript 

    function updateMenu(name){
    	var menu = new SCFile("menu")
    	var getMenu = menu.doSelect("name=\"" name "\"")
    	
    	if (getMenu == RC_SUCCESS){
    		menu.description.push("This is a test")
    		
    		menu.application.push("database")
    		menu.command[system.functions.lng(menu.description) -1]="pete"
    		menu.pname.push("name")
    		menu.pvalue.push("probsummary")
    		menu.condition.push("true")
    		
    		rc = menu.doAction("save")
    	}
    }
    updateMenu("ADMIN")

    and once I refresh the menu after running the script, the command works as expected and the item displays on the menu navigator.

    So, that may mean that, for your script, the way you're constructing one of the fields isn't quite correct, and the system is doing a built-in kind of autocorrect after saving.

    So, I'd recommend using the RAD Debugger.  Go to the menu you're updating and, in the debugger, check the contents of the $L.file variable.  Then, after saving the record, check the contents of the $L.file variable again.  Is something changing?  Like is the tool automatically adding quotation marks around anything, or performing some kind of code quality check - you know, like how it might put your parenthesis in different places or slightly change an expression... 

  • thanks for the help, my error was in this line.

    var file = new SCFile("MENU")

     I change "MENU" for "menu" and everyting works fine.