I have a client that would like to add an extra note field to a grid. If this is not possible, is there a way to have a large text field in a grid that uses a pop up window for editing the large amount of text in that field?
Priority:
1.) Add extra note field to grid, if possible.
2.) Failing #1, is there a way to add a popup window to edit a large standard user text field.
I believe the answer to your number 1 question is no. If the grid already has a note it cannot have another. I had this question come up before.
For #2, you should be able to do a smart panel that displays your field. Use a PXTextEdit and setup a new view for the panel to point to based on your selected/current row.
To add a smart panel (pop up panel) you need a handful of things in place. I prefer using AEF with graph and table extensions. There is documentation in the T200/T300 training material for these topics. In my example I add the note ability to the sales order page. I copied most of the logic from the existing "PO Link" button and panel which is the POSupplyOK PXAction and the currentposupply view (page SO301000).
First you need your new field which we will add to the sales line as an extension table/field:
[PXTable(typeof(SOLine.orderType), typeof(SOLine.orderNbr), typeof(SOLine.lineNbr), IsOptional = true)]
public class SOLineExtension : PXCacheExtension<SOLine>
{
#region XXMyNote
public abstract class xXMyNote : PX.Data.IBqlField
{
}
protected string _XXMyNote;
[PXDBString]
[PXUIField(DisplayName = "My Note")]
public virtual string XXMyNote
{
get
{
return this._XXMyNote;
}
set
{
this._XXMyNote = value;
}
}
#endregion
}
Then we need to create a new graph extension to add the view for the panel and the PXAction for the button to open the panel.
public class SOOrderEntryExtension : PXGraphExtension<SOOrderEntry>
{
public PXSelect<SOLine,
Where<SOLine.orderType, Equal<Current<SOLine.orderType>>,
And<SOLine.orderNbr, Equal<Current<SOLine.orderNbr>>,
And<SOLine.lineNbr, Equal<Current<SOLine.lineNbr>>>>>> MyPanelView;
public PXAction<SOOrder> myNoteAction;
[PXUIField(DisplayName = "Add Note", MapViewRights = PXCacheRights.Select, MapEnableRights = PXCacheRights.Update)]
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntryF)]
protected virtual IEnumerable MyNoteAction(PXAdapter adapter)
{
if (Base.Transactions.Current != null &&
MyPanelView.AskExt() == WebDialogResult.OK)
{
//extra stuff here if needed when OK is pushed
}
return adapter.Get();
}
}
now you need to "edit" the sales order page. you need to get your changes into a customization project and I usually go edit the page direct in visual studio under site\pages\so in this example. Then come back and paste in my code into the customization project by opening the project and performing the following steps:
Click on screens and the + sign to add a new screen
Enter SO301000 and save
Click on the SO301000 hyperlink to open the layout editor for sales order
Click Actions > Edit ASPX
Paste in your changes (mentioned below)
In the SO301000 page add the following:
[1] Add your DS Callback command within the PXDataSource tag
<px:PXDSCallbackCommand Name="MyNoteAction" Visible="False"
CommitChanges="true" DependOnGrid="grid" />
[2] Add the button to the toolbar above the sales line grid by adding the following to the PXGrid > ActionBar > CustomItems tags of the grid in the Document Details tab. (just search "PO Link" in the page to find this location easier or any of the listed buttons above the grid).
<px:PXToolBarButton Text="Add Note" DependOnGrid="grid">
<AutoCallBack Command="MyNoteAction" Target="ds" />
</px:PXToolBarButton>
[3] Add the panel code which represents what the panel will look like. You can play around with the sizing to fit your needs, just make sure you set your PXTextEdit to use MultiLine using the following example code. Look at the current sales order page to know where it fits into the page syntax:
<px:PXSmartPanel ID="PXSmartPanelNote" runat="server" Caption="My Note Panel Caption"
CaptionVisible="true" DesignView="Hidden" LoadOnDemand="true" Key="MyPanelView" CreateOnDemand="false" AutoCallBack-Enabled="true"
AutoCallBack-Target="formMyNote" AutoCallBack-Command="Refresh" CallBackMode-CommitChanges="True" CallBackMode-PostData="Page"
AcceptButtonID="btnMyNoteOk">
<px:PXFormView ID="formMyNote" runat="server" DataSourceID="ds" Style="z-index: 100" Width="100%" CaptionVisible="False"
DataMember="MyPanelView">
<ContentStyle BackColor="Transparent" BorderStyle="None" />
<Template>
<px:PXLayoutRule ID="PXLayoutRule44" runat="server" StartColumn="True" LabelsWidth="S" ControlSize="XM" />
<px:PXTextEdit ID="cstXXMyNote" runat="server" DataField="XXMyNote" TextMode="MultiLine"/>
</Template>
</px:PXFormView>
<px:PXPanel ID="PXPanel10" runat="server" SkinID="Buttons">
<px:PXButton ID="btnMyNoteOk" runat="server" DialogResult="OK" Text="OK"/>
</px:PXPanel>
</px:PXSmartPanel>
I have not fully tested the above but a quick slap together brought up the panel with no errors. I was using version 6.00.0955 but the same steps should work in all 5.X versions. Hope this helps.
Related
I have a form that has a layout like so:
<cms:FormField runat="server" ID="fMemberType" Field="MemberType" />
<cms:FormField runat="server" ID="fEmployeeCount" Field="EmployeeCount" />
<asp:Literal runat="server" ID="test" Text="test" />
<script runat="server">
protected void Page_PreRender(object sender, EventArgs e)
{
test.Text = fMemberType.Value.ToString();
}
</script>
However this produces Object reference not set to an instance of an object. because it can't find fMemberType for some reason. Looking for the correct way of doing this.
It's worth noting that the form fields are dropdowns with depending flags set so changing them triggers a postback, or at least it would, but I set the webpart container to be an update panel so it's AJAXing which means the data isn't available in the page POST params. I could turn this off and grab the data from the POST data but wanted to know if there was a better way first.
So you're fully defining the fields and everything for your form? Why not use the DataForm control and dynamically create the form for you? You can then get the data like so: (formUserSettings is a cms:DataForm)
EditingFormControl ctrState = formUserSettings.BasicForm.FieldEditingControls["UserState"] as EditingFormControl;
Then do some checking and assign the value:
if (ctrState != null)
{
fState = ctrlState.Value;
}
Most likely the form value is not set until after the pre-render. Alen Genzic's recommendation will show that. May want to try OnInit.
I've duplicated the search box webpart so i can make changes. I'm trying to add a localization string to the placeholder attribute.
This isn't working:
<cms:CMSTextBox ID="txtWord" runat="server" EnableViewState="false" MaxLength="1000"
ProcessMacroSecurity="false" placeholder="<%= CMS.Helpers.ResHelper.GetString("kff.Search--PlaceHolderCopy")%>" />
nor does this:
<cms:CMSTextBox ID="txtWord" runat="server" EnableViewState="false" MaxLength="1000"
ProcessMacroSecurity="false" placeholder='<%= CMS.Helpers.ResHelper.GetString("kff.Search--PlaceHolderCopy")%>' />
I have a JS Snippet that does work, but i'm hoping to avoid copy in JS files.
var $searchField = $('.searchTextbox');
if ($('body').hasClass('ENCA')) {
// search field placeholder copy
$searchField.attr('placeholder', 'Search For Stuff');
}
else {
$searchField.attr('placeholder', 'Recherche');
}
Can I add the localization string to the server tag, or should it be done in the code behind. I'm not sure the best location in the code behind for this either, I can't see a Page_Load block.
You could add the following line in the SetupControl method in the codebehind:
txtWord.Attributes.Add("placeholder", ResHelper.GetString("kff.Search--PlaceHolderCopy"));
You cannot really use the <%= syntax to set properties of server-side controls.
Also, please note that the CMSTextBox control has a WatermarkText property, which might be what you are looking for. It uses the TextBoxWatermarkExtender control from the AjaxControlToolkit library.
There is no need to duplicate the webpart and have duplicate code just for something this simple. Just create a different webpart layout for that webpart and add the following code above the Panel:
<script runat="server">
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
txtWord.Attributes.Add("placeholder", ResHelper.GetString("yourstring"));
}
</script>
I have a PXNumberEdit field which, on enter, adds a product to a grid on a customized SO301000 page. The insert works and the field
is emptied after the product is added. However, I would like to return the focus to that field. There doesn't seem to be
a SetFocus method for the field.
I have tried using the SO301000.cs code behind to set the focus, by adding a function for onValueChanged
to save the object as session variable and on pageload to set the focus on the saved object. This causes
the page to never finish loading.
I have also tried to use jquery in various ways but that hasn't worked either. Is there a way to do this?
The Hack
There is no SetFocus method in the framework like there is for SetEnabled/SetDisplayName/SetVisibility because most events are raised on focus changes and the framework ensures that the focus is not lost on every record updates. To set it up manually, you will then need to wait that the callback is completed before setting the focus.
To do so you will need to add a Javascript delegate to the list of event handlers to be called once the callback is over. The following code will set the focus on Customer Reference Nbr. every time Customer ID is changed (in SO301000):
<script type="text/javascript">
function FormView_Load() {
px_callback.addHandler(setFocusOnCustRef);
return;
}
var setFocus = false;
function CustomerID_ValueChanged() {
setFocus = true;
return;
}
function setFocusOnCustRef(context, error) {
if (setFocus === true)
{
setFocus = false;
var refNbr = px_alls["edCustomerRefNbr"];
refNbr.focus();
}
return;
}
</script>
<px:PXFormView ID="form" runat="server" DataSourceID="ds" Style="z-index: 100" Width="100%" DataMember="Document" Caption="Order Summary"
NoteIndicator="True" FilesIndicator="True" LinkIndicator="True" EmailingGraph="PX.Objects.CR.CREmailActivityMaint,PX.Objects"
ActivityIndicator="True" ActivityField="NoteActivity" DefaultControlID="edOrderType" NotifyIndicator="True"
TabIndex="14900" ClientEvents-Initialize="FormView_Load">
...
<px:PXSegmentMask CommitChanges="True" ID="edCustomerID" runat="server" DataField="CustomerID" AllowAddNew="True"
AllowEdit="True" DataSourceID="ds" ClientEvents-ValueChanged="CustomerID_ValueChanged"/>
...
</px:PXFormView>
Note that I added ClientEvents-Initialize="FormView_Load" on the PXFormView and ClientEvents-ValueChanged="CustomerID_ValueChanged" on the CustomerID's PXSegmentedMask.
As you can see this is a hack... When the setFocusOnCustRef is raised we have just refreshed the record (RowSelected) and we don't know what was changed prior to that (what field has been changed? was the change canceled?). The context that is passed to the delegate is only related to re-updating the records. To get a better understanding of what events are raised and in which order, please refer to the Update Scenario Event Model:
Thoughts and Tips
I don't know much of your implementation but I would like to point out that your needs look very similar to the function Add Stock Item that opens a SmartPanel with the buttons Add/Add & Close/Cancel. If the callback is raised from a button you will have meaningful information in your context and won't need to add a Javascript event on ValueChanged.
When you Save/Cancel. The focus will return to your first form element in the tab order (if successful).
You can set the Tab Order directly in the PXUIFieldAttribute :
PXUIField(DisplayName = "Asset ID", Visibility = PXUIVisibility.SelectorVisible, TabOrder=1)]
I am working on a customisation for CRM 2011. I have created a custom entity (which is based on activity so is an activity type aswell), created the relationship to account and on the account form created a custom navigation link pointing to a web resource which will power the custom display (this is just a html page with JavaScript).
The Web resource is used instead of a standard relationship link because it is doing a listings and preview display and not just the list view that the out of the box feature provides.
What i am trying to do is show the activities tab (the activities ribbon tab) on the accounts form, whenever the custom navigation link is pressed and a user goes into that section, in the same way it displays when you click the activities navigation link. I can't seem to find that much information on Tab Display Rules as i think that is the place (if this is possible) that it should be done.
Also, if there is a JavaScript way of doing it (although i have not found any) then that would work as well.
We have a solution.
DISCLAIMER This solution is not recommended (or supported) as it is a complete hack of epic proportions, but it solved the issue for us. this is a temporary bit of functionality as we build out a custom solution which will better fit the client, so it will not be there moving forwards which is why the hack worked for us. Additionally, a scripts could be written much better, we simply wanted to get it out the door.
NOTE: This solution will use some external libraries such as JQuery & CRM FetchKit
1) Adding a relationship to the custom object and account
We have a custom entity, and we created a 1:N relationship from the Account entity to our custom entity. What this does enables us to do is create a navigation link on the account form which points to an associated view of our custom entity. Once the link is in, we save and publish changes.
2) Get the id of the new navigation link created
The link above should now be on the form, so after saving and publishing we go to the live view and using the IE developer tools we get the id of the link as we need to catch the onclick and do some things with it later.
3) Decorating the onclick of the navigation link created
We have the id so and we want to decorate the onclick with some additional functionality. We create 2 new web resources:
"YourCustomEntity"_init : Javascript Web Resource: this will be used in the onload of the account form to get the link we created and alter the onclick to do some additional things
YourCustomEntity_page : HTML Page Web Resource: As per the original question, we have a additional requirement of showing a preview pane which is why we couldn't use the standard grid
Code for "YourCustomEntity"_init
Code is pretty basic and doesn't have any object caching or the like it was simply written to solve our problem. I have added comments to the code. Also Entity is a generic name, this was the name of our custom type. We set the original associated view to hidden instead of display:none because we still need it to load in the background as this is where the ribbon gets updated and loads, so there is definitely some script going on to do this, wish we knew it so we could just use that :)
function previewEntityInit(){
//Catch any navigation link click, we need this because we need to hide our
//grid when we are not on the custom entity page
$('.ms-crm-Nav-Subarea-Link, .ms-crm-FormSelector-SubItem').click(function () {
//Get the id of the link clicked and the frame injected object
var id = $(this).attr('id'),
cFrame = $('#entity_frame_preview');
//if the frame has already been injected
if(cFrame.length !== 0) {
//If we are not in the correct section
//(i.e. activities nav link was clicked) hide it
if (id !== 'nav_new_account_new_entity') {
cFrame.attr('style', 'display:none;');
}
else{
//The correct link was clicked, so show it
cFrame.attr('style', 'display:block; width:100%; height:100%;');
$('#new_account_new_entityFrame').attr('style', 'visibility: hidden;');
}
}
else{
//This is the first time the correct link has been clicked
//So we hide the default associated view and inject our
//own iframe point to the YourCustomEntity_page embedded resource we created
var src = Xrm.Page.context.getServerUrl();
if (id === 'nav_new_account_new_entity') {
$('#new_account_new_entityFrame').attr('style', 'visibility: hidden;');
$('<iframe />', {
id: 'entity_frame_preview',
src: src + '/WebResources/new_entity_page',
width: '100%',
height: '100%'
}).prependTo('#tdAreas');
}
}
});
YourCustomEntity_page
Not going to show all the code here, but we based ours on this link:
Preview Form Link
We changed it in the following ways:
Only the view name is hardcodes, the rest is taken via code (code below)
We don't use the second iframe opting instead to have a simple HTML section which loaded this (code for this and our load function below)
No Hard Coded Values
var server = Xrm.Page.context.getServerUrl();
var orgName = "";
// grid related settings
var entityId = window.parent.Xrm.Page.data.entity.getId();
var entityType = "1";
var areaView = "new_account_new_entity";
var internalGridElement = "crmGrid_new_account_new_entity";
var timeoutKey = null;
HTML For Preview
<div id="previewForm" style="display: none;">
<ol>
<li><span class="lbl">Account:</span><span id="lblAccount"></span></li>
<li><span class="lbl">Created:</span><span id="lblDate"></span></li>
<li><span class="lbl">Regarding:</span><span id="lblRegarding"></span></li>
<li><span class="lbl">Owner:</span><span id="lblOwner"></span></li>
</ol>
<div id="subject">
<span class="lbl">Subject:</span><span id="lblSubject" class="value"></span>
</div>
<div>
<span id="lblMsg"></span>
</div>
</div>
LoadPreview Code
This uses an external library called CRMFetchKit. The code actually does three fetch calls, this is not ideal and it should be one really (using joins, google it :)), but this wasn't working and was dragging so we decided just to go with three as this whole section will be replaced with a managed solution soon.
function LoadPreviewPane(entity) {
if (entity != null) {
$('#previewForm').show();
var fetchxml = ['<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">',
' <entity name="new_entity">',
'<attribute name="subject" />',
'<attribute name="description" />',
'<attribute name="createdon" />',
'<attribute name="new_account" />',
'<attribute name="ownerid" />',
' <filter type="and">',
' <condition attribute="activityid" operator="eq" value="' + entity.Id + '" />',
' </filter>',
' </entity>',
'</fetch>'].join('');
CrmFetchKit.Fetch(fetchxml).then(function (results) {
var account = window.parent.Xrm.Page.getAttribute("name").getValue(),
subject = results[0].getValue('subject'),
desc = results[0].getValue('description'),
created = new Date(results[0].getValue('createdon')),
theDate = created.getDate() + "/" + (created.getMonth() + 1) + "/" + created.getFullYear(),
owner = '',
regarding = '';
var fetchxml2 = ['<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">',
' <entity name="systemuser">',
'<attribute name="fullname" />',
' <filter type="and">',
' <condition attribute="systemuserid" operator="eq" value="' + results[0].getValue('ownerid') + '" />',
' </filter>',
' </entity>',
'</fetch>'].join('');
CrmFetchKit.Fetch(fetchxml2).then(function (users) {
owner = users[0].getValue('fullname');
$('#lblOwner').html(owner);
});
var fetchxml3 = ['<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">',
' <entity name="account">',
'<attribute name="name" />',
' <filter type="and">',
' <condition attribute="accountid" operator="eq" value="' + results[0].getValue('new_accountname') + '" />',
' </filter>',
' </entity>',
'</fetch>'].join('');
CrmFetchKit.Fetch(fetchxml3).then(function (regardings) {
regarding = regardings[0].getValue('name');
$('#lblRegarding').html(regarding);
});
$('#lblAccount').html(account);
$('#lblSubject').html(subject);
$('#lblMsg').html(nl2br(desc));
$('#lblDate').html(theDate);
});
}
}
I have a button control to which I want add image as well as hyperlink property, i.e it should be an image button with link to other source. I tried
<Button Click="OnNavigationRequest" ToolTip="Orkut">
<Image Source="C:\Documents and Settings\SaurabhS\My Documents\Visual Studio 2008 \Projects\SaurabhSinhaDemos\WPF_Zone\AddressBook\AddressBook\images\orkut.jpeg"/>
<Hyperlink NavigateUri="http://www.orkut.com">Orkut</Hyperlink>
</Button>
and in code behind:
AddHandler(Hyperlink.RequestNavigateEvent,
new RoutedEventHandler(OnNavigationRequest));
public void OnNavigationRequest(object sender, RoutedEventArgs e)
{
var source = e.OriginalSource as Hyperlink;
if (source != null)
Process.Start(source.NavigateUri.ToString());
}
But got the following error:
content set more than once...
How should I do it?
In your code, the Button element contains two child elements. The Button element can only take one child element.
Wrap Image and Hyperlink in a StackPanel or some other layout container and the error will go away (see Int3's answer for an example).
Try following
<Button>
<StackPanel Orientation="Horizantal">
<Image Source="path to the image"/>
<Hyperlink NavigateUri="http://www.orkut.com"/>
</StackPanel>
</Button>