Update a custom checkbox value(PO Screen) in a rowUpdated event handler from PORecieptEntry graph - customization

In Acumatica, I want to update UsrSendPONotifications checkbox(which is in PO screen) to true when I update a row in corresponding PO Receipt.
This is the code that I tried & it is not working. So , UsrSendPONotifications checkbox remains false.
Any idea about this?
protected void POReceipt_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
{
var row = (POReceipt)e.Row;
if (row == null) return;
else
{
POReceiptLine receiptLine = new PXSelect<POReceiptLine, Where<POReceiptLine.receiptNbr,
Equal<Required<POReceiptLine.receiptNbr>>>>(Base).Select(row.ReceiptNbr);
if(receiptLine == null) return;
else
{
POOrder poOrder = new PXSelect<POOrder, Where<POOrder.orderType,
Equal<Required<POOrder.orderType>>, And<POOrder.orderNbr,
Equal<Required<POOrder.orderNbr>>>>>(Base).Select(receiptLine.POType,
receiptLine.PONbr);
if(poOrder == null) return;
else
{
POOrderExt poExt = poOrder.GetExtension<POOrderExt>();
poExt.UsrSendPONotifications = true;
cache.SetValueExt<POOrderExt.usrSendPONotifications>
(poOrder,poExt.UsrSendPONotifications);
}
}
}

#AcumaticaZ Try using the existing cache for POOrder in POReceiptEntry. If you are working with regular PO this could work:
protected void POReceipt_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
{
var row = (POReceipt)e.Row;
if (row == null) return;
else
{
POReceiptLine receiptLine = new PXSelect<POReceiptLine, Where<POReceiptLine.receiptNbr,
Equal<Required<POReceiptLine.receiptNbr>>>>(Base).Select(row.ReceiptNbr);
if(receiptLine == null) return;
else
{
POOrder poOrder = new PXSelect<POOrder, Where<POOrder.orderType,
Equal<Required<POOrder.orderType>>, And<POOrder.orderNbr,
Equal<Required<POOrder.orderNbr>>>>>(Base).Select(receiptLine.POType,
receiptLine.PONbr);
if(poOrder == null) return;
else
{ poOrderUPD.Cache.SetValueExt<POOrderExt.usrSendPONotifications>
(poOrder,true);
}
}
}

Related

Select default value OrderType selector by user login on SOOrder Screen

On SOOrder Screen: I have OrderType: C1,C2,CS,SO and C1->userRole A, C2->userRole B,CS & SO->userRole Administrator. I want to select the default Ordertype by userlogin, if userlogin= Admin so show the selector are CS & SO.
This is the my Code Editor: SOOrderEntry (Sales Orders):
protected void SOOrder_OrderType_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
{
PXResult<PX.SM.UsersInRoles> user = PXSelect<PX.SM.UsersInRoles,
Where<PX.SM.UsersInRoles.username, Equal<Current<AccessInfo.userName>>>>.Select(Base);
if(user != null)
{
PX.SM.UsersInRoles role = user;
if(role.Rolename == "Administrator")
e.NewValue = "CS";
else
if(role.Rolename == "A")
e.NewValue = "C1";
if(role.Rolename == "B")
e.NewValue = "C2";
}
}
My result is: when login us role Administrator, it showed all the order type.
You can try as below
public class CustomOrderTypeSelectorAttribute : PXCustomSelectorAttribute
{
public CustomOrderTypeSelectorAttribute()
: base(typeof(SOOrderType.orderType))
{
}
public IEnumerable GetRecords()
{
PXResult<PX.SM.UsersInRoles> user = PXSelect<PX.SM.UsersInRoles,
Where<PX.SM.UsersInRoles.username, Equal<Current<AccessInfo.userName>>>>.Select(Base);
if(user != null)
{
PXResult<SOOrderType> orderTypes = null;
if(roleName == "Administrator")
{
orderTypes = PXSelect<SOOrderType,
Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>,
Or<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>>.Select(Base, "CS", "SO");
}
else if(roleName == "A")
{
orderTypes = PXSelect<SOOrderType,
Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.Select(Base, "C1");
}
else if(role.Rolename == "B")
{
orderTypes = PXSelect<SOOrderType,
Where<SOOrderType.orderType, Equal<Required<SOOrderType.orderType>>>>.Select(Base, "C2");
}
foreach (var item in orderTypes)
yield return item;
}
}
}
Then use cache attached to override OrderType property with custom select above

How to sync WebService operation in silverlight?

I am now on a project regarding controlling devices by using silverlight and web service(asmx page). The project flows like below:
pressing the button on the silverlight UI, it will send out a package by using socket to the middlewire. Then middlewire will accept the package and deconstructe it and return back another package to silverlight UI. I am using below code to load the button state, which will trigger database query:
private ButtonStateModel _buttonStateModel = new ButtonStateModel() { BtnOneImage = "Skins/images/flag/QU.png", BtnOneVisible = Visibility.Visible, BtnTwoVisible = Visibility.Collapsed };
public ButtonStateModel ButtonStateModel
{
get
{
ButtonStateModel btnState = null;
dataService.GetPR(BusEquipmentPermission.Control.RtuID, BusEquipmentPermission.Control.DevID, (result) =>
{
if (result != null && result.Count > 0)
{
var flag = result[0].PRFlag;
if (flag == 1)
{
btnState = new ButtonStateModel()
{
BtnOneImage = "Skins/images/flag/OP.png",
BtnOneVisible = Visibility.Visible,
BtnTwoImage = "Skins/images/flag/OFF.png",
BtnTwoVisible = Visibility.Visible
};
}
else if (flag == 2)
{
btnState = new ButtonStateModel()
{
BtnOneImage = "Skins/images/flag/OFF.png",
BtnOneVisible = Visibility.Visible,
BtnTwoImage = "Skins/images/flag/OR.png",
BtnTwoVisible = Visibility.Visible
};
}
}
});
return btnState;
}
set
{
if (value == _buttonStateModel)
{
return;
}
_buttonStateModel = value;
RaisePropertyChanged("ButtonStateModel");
}
}
Now the problem is, whenever I load the silverlight app, the button on the UI can't load its state correctly. I know the reason is because that the GetPR function is from webservice(asmx), it's very oddly that I can't do sync operation by using AutoResetEvent in silverlight generated client code:
public void GetPR(string rtuID, string devID, Action<List<BusControlPR>> action)
{
ServiceSoapClient proxy = new ServiceSoapClient();
proxy.GetPRAsync(rtuID, devID);
proxy.GetPRCompleted += (sender, args) =>
{
//I cannt do Sync Operation Here by using AutoResetEvent.
if (action != null)
action(args.Result.ToList());
};
}
I am using webservice (asmx page) instead of WCF ria service.
Above problem is what i meet, Anyone can give me some light?
The "GetPR" method is still running asynchronously, so the "ButtonStateModel" getter will return null immediately (the "completed" action will then have no effect). And, you do not want to use any kind of blocking inside your getters, as that will block the UI. Instead, you should put the "GetPR" in the initialization, and use the to set the "ButtonStateModel" property to the appropriate value:
public class TheViewModel
{
public ButtonStateModel ButtonStateModel
{
get
{
return _buttonStateModel;
}
set
{
if (value == _buttonStateModel)
{
return;
}
_buttonStateModel = value;
RaisePropertyChanged("ButtonStateModel");
}
}
public TheViewModel()
{
Initialize();
}
private void Initialize()
{
dataService.GetPR(BusEquipmentPermission.Control.RtuID, BusEquipmentPermission.Control.DevID, (result) =>
{
ButtonStateModel btnState = null;
if (result != null && result.Count > 0)
{
var flag = result[0].PRFlag;
if (flag == 1)
{
btnState = new ButtonStateModel()
{
BtnOneImage = "Skins/images/flag/OP.png",
BtnOneVisible = Visibility.Visible,
BtnTwoImage = "Skins/images/flag/OFF.png",
BtnTwoVisible = Visibility.Visible
};
}
else if (flag == 2)
{
btnState = new ButtonStateModel()
{
BtnOneImage = "Skins/images/flag/OFF.png",
BtnOneVisible = Visibility.Visible,
BtnTwoImage = "Skins/images/flag/OR.png",
BtnTwoVisible = Visibility.Visible
};
}
}
ButtonStateModel = btnState;
});
}
}

How to sort the selected items in a Sitecore Treelist?

Is there a way to always have the selected items in a Sitecore Treelist sorted alphabetically?
No, but you could look in to creating your own 'sorted treelist'. Someone asked a different question earlier today but it has basically the same answer:
Sitecore Tree list datasource - VersionExist
Sitecore lets you create custom field types. They can be based on existing ones, but with some added tweaks.
As mentioned in the answers to the other question, here are 2 articles which are good places to start:
Creating a Composite Custom Field
Apply Dynamic TreeList Source Parameters with the Sitecore ASP.NET CMS
Here's my implementation, which although long, is mostly copy-and-pasted from the decompiled Treelist code. I've highlighted which bits which are new in the Value property and the Add method:
namespace CustomFieldTypes
{
public class Treelist : Sitecore.Shell.Applications.ContentEditor.TreeList
{
public override string Value
{
get
{
// ---------- New code here -----------
var ids = base.Value.Split('|');
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var items = ids.Select(id => db.GetItem(id)).Where(item => item != null);
var orderedItems = items.OrderBy(item => item.Name);
var orderedIds = orderedItems.Select(item => item.ID.ToString());
return String.Join("|", orderedIds);
// ---------------------------------------
}
set
{
base.Value = value;
}
}
protected void Add()
{
if (this.Disabled)
return;
string viewStateString = this.GetViewStateString("ID");
TreeviewEx treeviewEx = this.FindControl(viewStateString + "_all") as TreeviewEx;
Assert.IsNotNull((object) treeviewEx, typeof (DataTreeview));
Listbox listbox = this.FindControl(viewStateString + "_selected") as Listbox;
Assert.IsNotNull((object) listbox, typeof (Listbox));
Item selectionItem = treeviewEx.GetSelectionItem();
if (selectionItem == null)
{
SheerResponse.Alert("Select an item in the Content Tree.", new string[0]);
}
else
{
if (this.HasExcludeTemplateForSelection(selectionItem))
return;
if (this.IsDeniedMultipleSelection(selectionItem, listbox))
{
SheerResponse.Alert("You cannot select the same item twice.", new string[0]);
}
else
{
if (!this.HasIncludeTemplateForSelection(selectionItem))
return;
SheerResponse.Eval("scForm.browser.getControl('" + viewStateString + "_selected').selectedIndex=-1");
ListItem listItem = new ListItem();
listItem.ID = Sitecore.Web.UI.HtmlControls.Control.GetUniqueID("L");
// ----- New Code Here -----------------------
bool listItemAdded = false;
for (int i = 0; i < listbox.Controls.Count; i++ )
{
ListItem control = (ListItem)listbox.Controls[i];
if (control == null)
return;
if (String.Compare(GetHeaderValue(selectionItem), control.Header) < 0)
{
listbox.Controls.AddAt(i, listItem);
listItemAdded = true;
break;
}
}
if (!listItemAdded)
{
Sitecore.Context.ClientPage.AddControl((System.Web.UI.Control)listbox, (System.Web.UI.Control)listItem);
}
// ------------------------------------------
listItem.Header = this.GetHeaderValue(selectionItem);
listItem.Value = listItem.ID + (object) "|" + (string) (object) selectionItem.ID.ToString();
SheerResponse.Refresh((Sitecore.Web.UI.HtmlControls.Control) listbox);
SetModified();
}
}
}
protected static void SetModified()
{
Sitecore.Context.ClientPage.Modified = true;
}
private bool HasIncludeTemplateForSelection(Item item)
{
Assert.ArgumentNotNull((object)item, "item");
if (this.IncludeTemplatesForSelection.Length == 0)
return true;
else
return HasItemTemplate(item, this.IncludeTemplatesForSelection);
}
private bool HasExcludeTemplateForSelection(Item item)
{
if (item == null)
return true;
else
return HasItemTemplate(item, this.ExcludeTemplatesForSelection);
}
private bool IsDeniedMultipleSelection(Item item, Listbox listbox)
{
Assert.ArgumentNotNull((object)listbox, "listbox");
if (item == null)
return true;
if (this.AllowMultipleSelection)
return false;
foreach (Sitecore.Web.UI.HtmlControls.Control control in listbox.Controls)
{
string[] strArray = control.Value.Split(new char[1]
{
'|'
});
if (strArray.Length >= 2 && strArray[1] == item.ID.ToString())
return true;
}
return false;
}
private static bool HasItemTemplate(Item item, string templateList)
{
Assert.ArgumentNotNull((object)templateList, "templateList");
if (item == null || templateList.Length == 0)
return false;
string[] strArray = templateList.Split(new char[1]
{
','
});
ArrayList arrayList = new ArrayList(strArray.Length);
for (int index = 0; index < strArray.Length; ++index)
arrayList.Add((object)strArray[index].Trim().ToLowerInvariant());
return arrayList.Contains((object)item.TemplateName.Trim().ToLowerInvariant());
}
}
}
When this is compiled and in your application you need to go to /sitecore/system/Field types/List Types/Treelist in the core database. In there, you need to fill in the Assembly and Class fields, and clear out the Control fields.
You could create a custom field and sort the items in the selected list using generics, then save the guids back to the field. I covered this in a recent blog post. There isn't that much coding involved.

Sitecore item does not contains all fields, why?

I have next code (just like prototype)
private void WriteDataToItems(Item rootitem, IQueryable<LanguageData> languageData, SC.Globalization.Language sclng)
{
if (rootitem == null)
return;
rootitem = IncVersion(rootitem);
Response.Write(string.Format("Item {0} - {1}<br/>", rootitem.DisplayName, rootitem.Paths.FullPath));
rootitem.Editing.BeginEdit();
try
{
foreach (Field fld in rootitem.Fields.Where(d => !d.Shared && !d.Name.StartsWith("__") && d.Name.Trim() != ""))
{
Response.Write(string.Format("Processing fld: - {0}<br/>", fld.ID.Guid.ToString()));
var data = languageData.FirstOrDefault(
d => (string.Compare(d.FieldName, fld.Name, true) == 0) && (string.Compare(d.ItemID, rootitem.ID.Guid.ToString(), true) == 0));
if (data != null)
{
string newValue = null;
switch (sclng.Name)
{
case "en":
newValue = data.En;
break;
case "nn-NO":
newValue = data.nnNO;
break;
case "sv-SE":
newValue = data.svSE;
break;
case "da-DK":
newValue = data.DaDK;
break;
case "de-DE":
newValue = data.deDE;
break;
default:
newValue = null;
break;
}
if (newValue != null)
{
Response.Write(string.Format("Save field with Id:{0} New Value:{1}<br/>", fld.ID.Guid, newValue));
fld.Value = newValue;
}
}
}
rootitem.Editing.EndEdit();
}
catch (Exception ex)
{
rootitem.Editing.CancelEdit();
}
foreach (Item cd in rootitem.GetChildren())
{
WriteDataToItems(cd, languageData, sclng);
}
}
and the issue that rootitem.Fields object do not contains all fields described in template, i just have a filing that it contain just fields that have some values but not contain fields with empty data
foreach (Field fld in rootitem.Fields.Where(d => !d.Shared && !d.Name.StartsWith("__") && d.Name.Trim() != ""))
how I can get all custom fields name ?
Should I use template data for it ?
Try to use Fields.ReadAll(); before looping through all fields:
rootitem.Fields.ReadAll();
foreach (Field fld in rootitem.Fields.Where(d => !d.Shared && !d.Name.StartsWith("__") && d.Name.Trim() != ""))
After you are using Fields.ReadAll() you can release memory used by these fields with method item.Fields.Reset();
Here is the code for ReadAll() and Reset():
/// <summary>
/// Reads all.
///
/// </summary>
public void ReadAll()
{
Template template = TemplateManager.GetTemplate(this._ownerItem);
if (template == null)
return;
TemplateField[] fields = template.GetFields();
this._fields = new Field[fields.Length];
for (int index = 0; index < fields.Length; ++index)
this._fields[index] = new Field(fields[index].ID, this._ownerItem);
}
/// <summary>
/// Resets this instance.
///
/// </summary>
public void Reset()
{
this._fields = (Field[]) null;
this._innerFields = (FieldList) null;
}
For the sake of performance, Sitecore will not give you all fields in the FieldCollection in the following code, only fields with explicit values on item level, including empty string.
However, you will be able to access fields with either Sitecore.Context.Item.Fields["title"] or with a PageEditor enabled Web Control such as sc:text: <sc:text field="title" runat="server" />
In order to have all the fields in the FieldCollection and iterate through them, make sure your code will include Sitecore.Data.Items.Item.Fields.ReadAll() call before your foreach.

The correct display name/field for a list item in a Sharepoint list (using Web Services)

I'm creating a program that uses SharePoint Web Services to query and show a Sharepoint list to the user. I can only show one column at a time, so I need to find a 'default column' or 'display column' to show. I know 'Title' is commonly used in many of the content types but I want this to be robust with any type of custom content type or list so I would like to find some way of querying the list to discover this field.
For example: I'm using SharePoint Manager 2010 here and looking at a Link Library (That doesn't have a Title field) but somehow it knows that the list item is called 'http://google.com'. How is it inferring this?
(source: adamburkepile.com)
Looks like DisplayName has quite a bit of logic behind it. Here is the code I got using Reflector:
public string DisplayName
{
get
{
if (!this.IsNew)
{
if ((!this.ParentList.AllowContentTypes && (this.ParentList.BaseType == SPBaseType.DocumentLibrary)) || (this.ParentList.AllowContentTypes && (this.ContentTypeId.IsNonDiscussionFolder || this.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Document))))
{
string str = (string) this.GetValue("BaseName", false);
if (!string.IsNullOrEmpty(str))
{
return SPHttpUtility.HtmlDecode(str);
}
}
SPField fieldByInternalName = this.Fields.GetFieldByInternalName("Title", false);
if (fieldByInternalName != null)
{
string fieldValueAsText = fieldByInternalName.GetFieldValueAsText(this.GetValue(fieldByInternalName, -1, false));
if (!string.IsNullOrEmpty(fieldValueAsText))
{
return fieldValueAsText;
}
}
if (this.ParentList.AllowContentTypes)
{
if (this.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Link))
{
SPFieldUrlValue value2 = new SPFieldUrlValue((string) this.GetValue("URL", false));
if (!string.IsNullOrEmpty(value2.Description))
{
return value2.Description;
}
if (!string.IsNullOrEmpty(value2.Url))
{
return value2.Url;
}
}
if (this.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Message))
{
Guid discussionTitleLookup = SPBuiltInFieldId.DiscussionTitleLookup;
SPField fld = this.Fields[discussionTitleLookup];
string str3 = fld.GetFieldValueAsText(this.GetValue(fld, -1, false));
if (!string.IsNullOrEmpty(str3))
{
return str3;
}
}
}
if (this.ParentList.BaseType != SPBaseType.Survey)
{
using (IEnumerator enumerator = this.Fields.GetEnumerator())
{
SPField field3;
string str5;
while (enumerator.MoveNext())
{
field3 = (SPField) enumerator.Current;
if (field3.GetFieldBoolValue("TitleField"))
{
goto Label_00C6;
}
}
goto Label_016F;
Label_00BB:
if (!(field3 is SPFieldMultiLineText))
{
return str5;
}
goto Label_00ED;
Label_00C6:
str5 = field3.GetFieldValueAsText(this.GetValue(field3, -1, false));
if (string.IsNullOrEmpty(str5))
{
goto Label_016F;
}
goto Label_00BB;
Label_00ED:
if (str5.Length <= 0xff)
{
return str5;
}
return str5.Substring(0, 0xff);
}
}
SPContext context2 = SPContext.Current;
if ((context2 == null) || (context2.FormContext.FormMode != SPControlMode.Edit))
{
return SPResource.GetString("ViewResponseTitle", new object[] { this.ID.ToString("N0", this.Web.Locale) });
}
return SPResource.GetString("ToolBarMenuRespondToSurvey", new object[0]);
}
SPContext current = SPContext.Current;
if (this.ParentList.BaseType != SPBaseType.Survey)
{
if ((current != null) && current.FormContext.IsNonDiscussionFolder)
{
return SPResource.GetString("ButtonTextNewFolder", new object[0]);
}
return SPResource.GetString("NewFormTitleNewItem", new object[0]);
}
return SPResource.GetString("ToolBarMenuRespondToSurvey", new object[0]);
Label_016F:
return SPResource.GetString("NoTitle", new object[0]);
}
}