How can I read data from the below code? Right now we are redirecting to a particular screen, but before redirecting we need to get some values from this graph object. This is the sample code from the JournalEntry base graph. I tried to get the view names but that didn't work
IDocGraphCreator creator = GetGraphCreator(doc.Module, doc.BatchType);
if (creator != null)
{
PXGraph graph = creator.Create(doc);
if (graph != null) //how to read data from this object
{
throw new PXRedirectRequiredException(graph, true, "")
{
Mode = PXBaseRedirectException.WindowMode.NewWindow
};
}
}
I would use PXGraph.CreateInstance< Newgraph >(); to create the graph, and then you can manipulate before redirecting. Here is an example of viewing a customer from the CCTransactionsHistoryEnq screen.
CustomerMaint graph = PXGraph.CreateInstance<CustomerMaint>();
graph.BAccount.Current = graph.BAccount.Search<Customer.bAccountID>(pmInstance.BAccountID);
if (graph.BAccount.Current != null)
{
throw new PXRedirectRequiredException(graph, true, Messages.ViewCustomer) { Mode = PXBaseRedirectException.WindowMode.NewWindow };
}
You should be able to read the information as well from the graph, or call other functions on the graph this way as well.
Related
I had wrote some code for creating po via code, but it faild with error message: "CS Error: Cannot generate the next number for the sequence."
How can I fix this? Anything I missed? Thx for helping!
protected void createPO() {
POOrder order = new POOrder();
POOrderEntry graph = PXGraph.CreateInstance < POOrderEntry > ();
order.OrderType = "Normal";
order.OrderDesc = "some text";
order.EmployeeID = 215;
order.Hold = false;
var branch = (Branch)PXSelect<Branch, Where<Branch.branchCD, Equal<Required<Branch.branchCD>>>>.Select(Base, "WEST");
graph.FieldDefaulting.AddHandler<POOrder.branchID>((s, e) =>
{
e.NewValue = branch.BranchID;
e.Cancel = true;
});
order.VendorID = 79;
order = graph.CurrentDocument.Insert(order);
graph.CurrentDocument.Update(order);
graph.Actions.PressSave();
throw new PXRedirectRequiredException(graph, null);
}
Try to simply it first to see if something like this works...
protected void createPO()
{
var graph = PXGraph.CreateInstance<POOrderEntry>();
var order = graph.Document.Insert(new POOrder());
order.OrderType = POOrderType.RegularOrder; // This is the default so not necessary
order.OrderDesc = "some text";
order.EmployeeID = 215;
order.Hold = false;
order.VendorID = 79;
graph.Document.Update(order);
graph.Actions.PressSave();
throw new PXRedirectRequiredException(graph, null);
}
Using the Document view in place of the CurrentDocument view which is based on the current record of Document. Document is the primary view and the primary view should be used.
Also for the purchase order type the attribute related to the list values should be used for the stored value of the database (vs what you had was the displayed list value). For example order.OrderType = POOrderType.RegularOrder. Also this is the default value for a PO so it is not necessary to set this value unless you want a different constant found in the POOrderType class.
My goal is, from a given screen :
- Add lines to the Adjustments tab of the payment & application graph
- Release
I tried to do this :
override public void createLettering(List<ARRegister> lines)
{
string refNbr = "";
foreach (ARRegister line in lines)
{
if (line.DocType == "PMT") refNbr = line.RefNbr;
}
// Get the paymententry graph, and add the invoice
ARPaymentEntry graphPmt = PXGraph.CreateInstance<ARPaymentEntry>();
ARPayment pmt = PXSelect<ARPayment, Where<ARPayment.refNbr, Equal<Required<ARPayment.refNbr>>,
And<ARPayment.docType, Equal<Required<ARPayment.docType>>>>>
.Select(this,refNbr, "PMT");
graphPmt.Document.Current = pmt;
if (pmt == null) throw new PXException(Constantes.errNotFound);
//pmt.CuryOrigDocAmt = 0m;
//graphPmt.Document.Update(pmt);
ARAdjust adj = new ARAdjust();
foreach(ARRegister line in lines)
{
if (line.DocType == "INV")
{
adj = new ARAdjust();
adj.AdjdDocType = line.DocType;
adj.AdjdRefNbr = line.RefNbr;
graphPmt.Adjustments.Insert(adj);
}
}
PXAdapter adapter = new PXAdapter(new PXView(graphPmt,true, graphPmt.Document.View.BqlSelect));
graphPmt.Persist();
graphPmt.Release(adapter);
}
My problem is I think my adapter gets every single ARPayment in it and thus tries to release them all. (The output of this function is : long processing time and then tells me 'PaymentMethod can't be null', but the paymentMethod of my graphPmt.Document is not null when I check in debug).
so How do I pass a correct PXAdapter to the Release(PXAdapter adapter) method of the PaymentEntry graph, from another custom graph of mine ?
I would think you should be able to call the action such as...
graphPmt.release.Press();
I have not tested this but I recall doing something like this for other actions in the past.
I have a graphical editor which extends GraphicalEditorWithFlyoutPalette.
There could be appear different markers, so it would be nice, if there is any possibility to connect the marker with the EditPart.
I think one possibility is to extend the TableViewer and the corresponding cell classes. But perhaps there is a better and more easier way.
I create my test markers like following:
IResource resource = (IResource) input.getAdapter(IResource.class);
try
{
IMarker marker = resource.createMarker(IMarker.PROBLEM);
marker.setAttribute(IMarker.TEXT, "text");
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
marker.setAttribute(IMarker.MESSAGE, "message");
}
catch (CoreException e)
{
e.printStackTrace();
}
input is my IEditorInput.
In my first attempt, I was trying to extends the ExtendedMarkersView, which fails because it is an internal class.
Another way was to write the view and all corresponding stuff new, but it seems to be senseless.
So I found a work around based on https://stackoverflow.com/a/10501971/390177.
While creating the IMarker, I set additional attributes to link the corresponding data object. With the help of the object I can search for the AbstractGraphicalEditPart with the EditPartRegistry.
After that it is possible to create a selection on the EditPart and reveal to it.
#Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
IStructuredSelection s = (IStructuredSelection) selection;
if (s.getFirstElement() instanceof MarkerItem) {
MarkerItem marker = (MarkerItem) s.getFirstElement();
if (marker != null && marker.getMarker() != null) {
IMarker iMarker = marker.getMarker();
AbstractGraphicalEditPart editPart = null;
DataObject object ...
editPart = (AbstractGraphicalEditPart) getGraphicalViewer().getEditPartRegistry().get(object);
if (editPart != null) {
StructuredSelection eSelection = new StructuredSelection(editPart);
getGraphicalViewer().setSelection(eSelection);
// once selected if you want to get it so the
// graphicalviewer scrolls to reveal the part on the
// screen
getGraphicalViewer().reveal(editPart);
}
}
} else {
super.selectionChanged(part, selection);
}
}
When I like an article on our website (www.potatopro.com) with a Facebook like and a facebook sharebutton the wrong website data is being fetched.
Either you are not able to change the picture or in the other case facebook fetches the navigation instead of the content.
To my understanding I have to implement facebook's open graph protocol meta-tags on our site. But how do I do that for a sharepoint based website?! Please advice!
You can add a webpart to the pagelayout that your page is using. In the webpart you add a function that finds the title, content and image on the page and writes metatags to the masterpage that the page is using. Here is an example of the function...
protected override void Render(HtmlTextWriter writer)
{
if (SPContext.Current != null && SPContext.Current.ListItem != null)
{
SPListItem item = SPContext.Current.ListItem;
var title = item["Title"];
if (title != null)
{
writer.WriteBeginTag("meta");
writer.WriteAttribute("property", "og:title");
writer.WriteAttribute("content", title.ToString());
writer.WriteEndTag("meta");
}
var pageContent = item["PublishingPageContent"];
if (pageContent != null)
{
string strippedPageContent = Regex.Replace(pageContent.ToString(), #"<(.|\n)*?>", string.Empty);
writer.WriteBeginTag("meta");
writer.WriteAttribute("property", "og:description");
writer.WriteAttribute("content", strippedPageContent);
writer.WriteEndTag("meta");
}
var pageImage = item["PublishingPageImage"];
if (pageImage != null)
{
ImageFieldValue pageImageValue = pageImage as ImageFieldValue;
if (pageImageValue != null)
{
var url = pageImageValue.ImageUrl;
writer.WriteBeginTag("meta");
writer.WriteAttribute("property", "og:image");
writer.WriteAttribute("content", url);
writer.WriteEndTag("meta");
}
}
}
}
I'm struggling with the SharePoint 2007 AfterProperties. I've a people input field, where several people can be added.
On the ItemUpdating event I now need to determine which users were added, removed or stayed the same.
Unfortunately this becomes quit difficult, as the id of the untouched users turns to -1 in the AfterProperties, so that I cant not use SPFieldUserValueCollection to find the user.
An example. properties.ListItem["AssignedTo"].ToString() shows:
1;#domain\user1;#2;#domain\user2
properties.AfterProperties["AssignedTo"].ToString() shows:
-1;#domain\user1;#-1;#domain\user2;#3;#domain\user3 <-Added a user
I planned to use following code, to determine removed and added users:
foreach (SPFieldUserValue oldUser in oldUserCollection)
{
if (newUserCollection.Find(x => x.LookupId == oldUser.LookupId) == null)
{
RemoveRole(aListItem, oldUser.User, roleDefCollection[workerRoleName]);
}
}
foreach (SPFieldUserValue newUser in newUserCollection)
{
if(oldUserCollection.Find(x => x.User.LoginName == newUser.LookupValue) == null)
{
AddRole(aListItem, newUser.User, roleDefCollection[workerRoleName]);
}
}
How can I archive, that the AfterProperties show the right lookupid?
Solved the problem by myself. Instead of using the SPFieldUserCollection I'm now using a list and try to parse all the information by myself out of the string.
Regex reg = new Regex(#"\;\#");
string[] usernameParts = reg.Split(usernames);
List<SPUser> list = new List<SPUser>();
int id;
foreach (string s in usernameParts)
{
if (!string.IsNullOrEmpty(s))
{
if (!Int32.TryParse(s, out id))
{
if (list.Find(x => x.ID == spweb.Users[s].ID) == null)
list.Add(spweb.Users[s]);
}
else
{
if (Convert.ToInt32(s) != -1)
{
if (list.Find(x => x.ID == Convert.ToInt32(s)) == null)
list.Add(spweb.Users.GetByID(Convert.ToInt32(s)));
}
}
}
}