Xrm.Page.data.getIsValid() return different values for users with different roles - dynamics-crm-2013

I have a ribbon button "ABC" on Opportunity form.
OnClick of "ABC" following function is triggered:
function popup()
{
if (!Xrm.Page.data.getIsValid()) return;
-------
-------
-------
}
I have tested following steps.
If user has role other than system Administrator.
open opportunity record, click on "ABC" button, popup() function is triggered. Xrm.Page.data.getIsValid() return true
Open opportunity record, click on "ABC" button,Edit record, save record, popup() function is triggered. Xrm.Page.data.getIsValid() return false
If user has role system Administrator.
open opportunity record, click on "ABC" button, popup() function is triggered. Xrm.Page.data.getIsValid() return true
Open opportunity record, click on "ABC" button,Edit record, save record, popup() function is triggered. Xrm.Page.data.getIsValid() return true
Please help me why getIsValid() returns diffrent values if user is not administrator

Where did you find getIsValid()? That doesn't appear in the documentation. So I'm guessing its an internal and therefore unsupported function, e.g. you shouldn't expect it to work.
Suggest reworking the design using only functions listed on the MSDN.

Related

MS Access one form to select table values and use to populate multiple fields on other form?

I have a table called GL_Account and IM_Productline
The table IM_Productline has various fields that need to be populated with a value from the field GL_Account.AccountKey (i.e. IM_ProductLine.InventoryAcctkey and IM_ProductLine.CostOfGoodsSoldAcctKey)
To populate the IM_ProductLine table I made a form "Product Line Maintenance" with all the fields. To populate the field IM_ProductLine.InventoryAcctkey I put a (magnifying glass) button behind the field with the following code:
Private Sub CMD_Select_GL_Account_Click()
Me.Refresh
If IsNull(Select_ProductType) Then
'do nothing
Else
Forms![Product Line Maintenance].InventoryAcctkey = Me.SelectGLAccountKey.Column(0)
Forms![Product Line Maintenance].Refresh
End If
DoCmd.Close
End Sub
So the button opens a form Called "Select GL Account" with a combo box that enable to SELECT GL_Account.AccountKey, GL_Account.Account, GL_Account.AccountDesc
FROM GL_Account; and when the OK button is clicked it writes the value from GL_Account.AccountKey to IM_ProductLine.InventoryAcctkey, closes the form "Select GL Account" and then refreshes the form "Product Line Maintenance" so the account number and description become visible for the user.
This all work fine but here's my question:
Now rather than creating a new form for every account field I need to populate (i.e. "Select Inventory GL Account" select "Cost Of Goods Sold GL Account" etc) I'd prefer to use the form "Select GL Account" to select and populate the 11 different account fields. So behind each xxxAcctkeyfield on form "Product Line Maintenance" is a (magnifying glass) button that when clicked pulls up the form "Select GL Account" and when "OK" is clicked it writes the selected AccountKey to the correct field on form "Product Line Maintenance"?
I'd greatly appreciate anyone's efforts to understand what I am trying to explain and point me in the right direction.
Ok, there is the issue that all 11 fields should not require to be "copied" since you have a relational database (you would ONLY store the row PK ID of that selection in the current report. (a so called FK (foreign key) value). That way, say you want to change the choice? Well then you could pop up that form - search + select the one record with all that information, and then upon return ONLY store the one value.
So, I would give some thoughts to the above - you want to leverage the relational database features. And as a result, you don't need to "copy" all that data. This is not much different then say creating a invoice. I can create the new invoice, but all of the address information, and the customer that this ONE invoice belongs to? Well, that is one column with a FK value that points to the customer. Once I select that one customer, then display of the customer name + address can be say a sub form or some such - but no need exists to "copy" that information. It would also means with near zero code, you could move a invoice between customers!!! - (just change the one fk column with to the new/different customer ID (PK) value.
Now, back to the question at a hand?
You can certainly pop up a form, let the user select, enter, pick and do whatever. And THEN you can have the calling code grab + pick out the values from that form.
The way you do this? It involves a not too wide known trick.
The code that calls the form can simply open that form as a dialog form. This will HALT the calling code, the user does whatever, and when done the calling code will THEN continue. Not only does the calling code continue, but it can get/grab/pull/take any values from that pop up form WIHOUT having to use global vars.
The approach is thus thus:
dim strF as string
strF = "frmPopAskInfo"
docmd.OpenForm strF,,,,,,acDialog
' above code waits for user input
if application.AllForms(strF).IsLoaded = true then
' user did not cancel, get values from form
me!AccountNo = forms(strf)!AccountNumber
etc. etc. etc.
docmd.Close acForm,strF
end if
Now the only other issue? Well, the "ok" button on the popup for DOES NOT close the form, what it does is set visible = False. This will kick the form out of dialog mode.
me.Visible = False
So, if the user hits the cancel buttton (close form) or hits the X upprer right (close form), then the form will NOT be loaded when your calling code continues. But, if they hit OK button, then you don't close the form, but ONLY set visbile = false.
This allows the calling code to continue, you are free to get/grab/take values from that form, and then once done, you close the form.
So a form close in that popup = user canceled the form.
So, a popup form, and even a modal form? They do NOT halt the VBA calling code, but a acDialog form does!
You can thus place 2 or 5 little buttons that pops up this form, the user can pick/choose/select/enter values. When they hit ok, your calling code continues, and you are free to pull values from that form. So while all 3-4 buttons might pop up that form, each individual button launch of the form can have code that follows and updates the given control the pop button was placed beside.

Prevent Revit from receiving a delete command in modeless form

I am desperately trying to prevent revit from receiving a delete command while in a modeless form (one that was displayed with Show() and not Showdialog()), but I can’t seem to be able to stop it.
My problem is my form contains textboxes: its core function requires the user to be able to navigate (pan and zoom) in revit without having to close and reopen the form.
But as soon as the user presses delete on any textbox text revit thinks the user has entered a delete command in the main window, and this could lead to accidental deletions.
Note the api queries a revitdb based on selected entities (families) and is then they are able to rename the family type or family name, using a textbox and ‘apply’ button. But as soon as they hit the delete button on the keyboard, guess what – the entity is deleted in revit.
I’ve spend 10 hours on this and it could turn out to be catastrophic to my plans.
Answer my own question: The workaround is to just 'pin' selected elements when user clicks on textbox.
private void textBox3_MouseClick(object sender, MouseEventArgs e)
{
//find selected items
Selection sel = uidoc.Selection;
ICollection<ElementId> ids = sel.GetElementIds();
foreach (ElementId id in ids)
{
Element el = doc.GetElement(id);
el.Pinned = true;
}
}
Then unpin when user leaves field (unsatisfying andw.

Code "delete my account" button

Im using vb 2013. I tried to code my delete button after adding SQL delete in my Database. I wrote code in the class (I called it userFunc) calling the SQL DeleteItYourself with the variable DeleteIt. I created button with the toolbox and double clicked it, now I'm lost. I have session in the Login button to make sure it presents the user nickname. I redirected it to the homepage when the "I want to delete my account" located. Iactually don't know what to do with the button. I want it to call the function DeleteIt, but before the function Delete I want it to ask the user with some pop up alert if he's sure. Any ideas how to code my button?
(I'm a high school student and it's my project, they don't ACTUALLY teach us Java, unfortunately... They tell us to copy paste and try to understand)
Use this as a starting point:
If MsgBox("Are you sure you want to delete your account? This cannot be undone.", _
(MsgBoxStyle.Critical + MsgBoxStyle.OkCancel), _
"Confirm Account Deletion") = MsgBoxResult.Ok Then
UserFunc(DeleteIt)
End If
MsgBox displays a message box to the user, waits for a response, and returns the value of the button pressed. In the code above, the three arguments are:
The message to display
The style of the message box. Note how these are numeric values and can be added.
The title of the window.

vb.net, I have only one textbox in the form and the validate event won't fire

I'm trying to make a text box where you can enter a page number and the form will change. I'm using a textbox to allow the user to enter a page number and I want the form to change when the are no longer actively editing the textbox, the problem is that the textbox is the only editable control in the form so it never loses focus and the validating event never fires. Is there any way to do this?
As matzone said use the keypress but not for the page number keys.
For example, say your user wants to goto page "51", then the user can type 51 and press the return key.
Have the events fire on the return key,
private void TextBox1_KeyDown(object sender, KeyEventArgs e)
{
//13 is the keycode for Return
If (e.KeyCode == 13)
{
//SuperAweomseEventGoesHere
}
}
Use a button as was mentioned to indicate the user wants to load a new page.
Use the validating event to make sure the user entered a valid value.
Alternatively:
If your page numbers are all double digits you could also use the TextChanged event and keep checking if the text value equals a page number. Having at least 2 digits is important since 1 will load a page and the user won't be able to load 10
Another alternative:
Use a NumberUpDown control or a combobox so the user is restricted to the proper values

Never ending loop while setting focus to control on validating event in cantrol validating event

I am writing below code for validating compulsary field account no. in form.
User's requirement is set focus back on field when error comes :
If txtAccountNo = "" Then
MessageBox.Show("Account no filed can't be left empty")
txtAccountNo.SetFocus
Exit Sub
End If
It's working properlly. But suppose user don't want to fill form and exiting from aaplication.
Message box keep on appearing till user enters account no.
How can I avoid this situation?
Please help.
Set a flag to indicate user has seen messagebox. Check the flag to prevent any future messagebox. Make sure the flag is set before setting focus back to textbox e.g.
dim bMsgBox as boolean=false
If txtAccountNo = "" and bMsgBox = false Then
MessageBox.Show("Account no filed can't be left empty")
bMsgBox=true
txtAccountNo.SetFocus
Exit Sub
End If
You could put all the validation rules in one function / procedure / subrutine (I'm not familiar with VB, mostly C++ / C# user). Then call this function only when user is committing the data filled in, and set focus to first control with mandatory data not filled or invalid data entered.
Say you have a form with 3 controls to be filled in:
a date control not mandatory - dteDate
a text box mandatory - txtAccoutInfo
a text box mandatory - txtAddress
and 2 buttons:
button Save and button Cancel.
When 'Save' button is pressed you first call the function / procedure to validate user input. If date entered is invalid in dteDate, you set focus on it and return / exit the function; if no text is entered in txtAccountInfo then set focus on it and return / exit the function; if no text is entered in txtAddress then set focus on it and return / exit.
When 'Cancel' is pressed you don't call this function, but just quit.