Highlighted
Absent Member.
Absent Member.
398 views

Adding new menu entry from Javascript

Jump to solution

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));

		}
	}
}

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: Adding new menu entry from Javascript

Jump to solution

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... 

View solution in original post

4 Replies
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: Adding new menu entry from Javascript

Jump to solution

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.

0 Likes
Highlighted
Absent Member.
Absent Member.

Re: Adding new menu entry from Javascript

Jump to solution

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.

0 Likes
Highlighted
Acclaimed Contributor.. Acclaimed Contributor..
Acclaimed Contributor..

Re: Adding new menu entry from Javascript

Jump to solution

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... 

View solution in original post

Highlighted
Absent Member.
Absent Member.

Re: Adding new menu entry from Javascript

Jump to solution

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

var file = new SCFile("MENU")

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

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.