How to Make Visible Command Button

Stivan_dsouza21Stivan_dsouza21 Member Posts: 218
How to Make Visible Command Button to some user.

1) I have created a a new role. If that role exist in that user id. then only the Command Button should get visible.

2) i have created the 2 command button as "DONE" and "EDIT"

3) i have written code as follows:

Form - OnOpenForm Trigger

user.GET(USERID);
memberof.RESET;
memberof.SETRANGE(memberof."User ID",USERID);
memberof.SETRANGE(memberof."Role ID",'TC UPDATION');
IF memberof.FINDFIRST THEN
BEGIN
CurrForm.Done.Visible:= FALSE;
CurrForm.Edit.Visible:= FALSE;
END;

But the above code is not working
can somebody help me out.
Thanks & Regards,
Stivan D'souza

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Should it be
    CurrForm.Done.Visible:= TRUE;
    CurrForm.Edit.Visible:= TRUE;

    If role found?
  • krikikriki Member, Moderator Posts: 9,110
    It does not work if you use Windows logins.
    Give this one a look : http://www.mibuso.com/forum/viewtopic.php?t=38353
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Stivan_dsouza21Stivan_dsouza21 Member Posts: 218
    I have done the necessary Changes but its saying

    Microsoft Dynamics NAV Classic
    You have specified an unknown variable.

    Done

    Define the variable under 'Global C/AL symbols'.

    OK
    Thanks & Regards,
    Stivan D'souza
  • mohana_cse06mohana_cse06 Member Posts: 5,504
  • Stivan_dsouza21Stivan_dsouza21 Member Posts: 218
    Its a Command Button.
    Thanks & Regards,
    Stivan D'souza
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    sorry..
    I mean Name property for command button..
  • Stivan_dsouza21Stivan_dsouza21 Member Posts: 218
    Yes.
    But if role is not specified then also its visible.
    Thanks & Regards,
    Stivan D'souza
  • Stivan_dsouza21Stivan_dsouza21 Member Posts: 218
    Thanks Mohana.
    Its Done.


    user.GET(USERID);
    memberof.RESET;
    memberof.SETRANGE(memberof."User ID",USERID);
    memberof.SETRANGE(memberof."Role ID",'TC UPDATION');
    IF memberof.FINDFIRST THEN
    BEGIN
    CurrForm.Done.VISIBLE:= TRUE;
    END ELSE
    CurrForm.Done.VISIBLE:= FALSE;

    user.GET(USERID);
    memberof.RESET;
    memberof.SETRANGE(memberof."User ID",USERID);
    memberof.SETRANGE(memberof."Role ID",'TC UPDATION');
    IF memberof.FINDFIRST THEN
    BEGIN
    CurrForm.Edit.VISIBLE:= TRUE;
    END ELSE
    CurrForm.Edit.VISIBLE:= FALSE;
    Thanks & Regards,
    Stivan D'souza
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Why do you need 2 times?
    user.GET(USERID);
    memberof.RESET;
    memberof.SETRANGE(memberof."User ID",USERID);
    memberof.SETRANGE(memberof."Role ID",'TC UPDATION');
    IF memberof.FINDFIRST THEN BEGIN
      CurrForm.Done.VISIBLE:= TRUE;
      CurrForm.Edit.VISIBLE:= TRUE;
    END ELSE BEGIN
      CurrForm.Done.VISIBLE:= FALSE; 
      CurrForm.Edit.VISIBLE:= FALSE;
    END;
    
  • Stivan_dsouza21Stivan_dsouza21 Member Posts: 218
    Thanks Mohana i have necessary changes as per request and it working fine.

    =D>
    Thanks & Regards,
    Stivan D'souza
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Or
    memberof.RESET;
    memberof.SETRANGE(memberof."User ID",USERID);
    memberof.SETRANGE(memberof."Role ID",'TC UPDATION');
    CurrForm.Done.VISIBLE:= memberof.FINDFIRST;
    CurrForm.Edit.VISIBLE:= memberof.FINDFIRST;
    
    :thumbsup:
  • SogSog Member Posts: 1,023
    Or
    memberof.RESET;
    memberof.SETRANGE(memberof."User ID",USERID);
    memberof.SETRANGE(memberof."Role ID",'TC UPDATION');
    CurrForm.Done.VISIBLE:= memberof.FINDFIRST;
    CurrForm.Edit.VISIBLE:= memberof.FINDFIRST;
    
    :thumbsup:
    I prefer only one findfirst
    memberof.RESET;
    memberof.SETRANGE(memberof."User ID",USERID);
    memberof.SETRANGE(memberof."Role ID",'TC UPDATION');
    CurrForm.Done.VISIBLE:= memberof.FINDFIRST;
    CurrForm.Edit.VISIBLE := currform.done.visible
    

    But I once created a function in a codeunit that is "hasrole"
    The same code applies, but a parameter with the rolename and a boolean return. Bam you can use it anywhere
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • dansdans Member Posts: 148
    memberof.RESET;
    memberof.SETRANGE(memberof."User ID",USERID);
    memberof.SETRANGE(memberof."Role ID",'TC UPDATION');
    CurrForm.Done.VISIBLE:= memberof.FINDFIRST;
    CurrForm.Edit.VISIBLE:= memberof.FINDFIRST;
    
    :thumbsup:
    Sog wrote:
    I prefer only one findfirst
    memberof.RESET;
    memberof.SETRANGE(memberof."User ID",USERID);
    memberof.SETRANGE(memberof."Role ID",'TC UPDATION');
    CurrForm.Done.VISIBLE:= memberof.FINDFIRST;
    CurrForm.Edit.VISIBLE := currform.done.visible
    

    or this :P
    memberof.RESET;
    memberof.SETRANGE(memberof."User ID",USERID);
    memberof.SETRANGE(memberof."Role ID",'TC UPDATION');
    CurrForm.Done.VISIBLE:= NOT memberof.ISEMPTY;
    CurrForm.Edit.VISIBLE := currform.done.visible
    
    Microsoft Certified IT Professional for Microsoft Dynamics NAV

    Just a happy frood who knows where his towel is
Sign In or Register to comment.