In Acumatica how do I save the branch location at the top of the page to a field - branch

I want to have the system put the branch (red arrow) in the field (purple arrow) when I create a new record. I know that the red arrow is the BranchCD field but I cannot find where to grab the selected BranchCD when I am looking through any of the code. It seems like this field is hidden somewhere. Can you help me out and point me in the right direction to look?

A little complicated, but surely doable with couple static methods from the PX.Data.PXAccess class:
public string GetBranchName()
{
var branchID = PXAccess.GetBranchID();
if (branchID != null)
{
var userName = PXAccess.GetUserName();
var branchInfo = PXAccess.GetBranches(userName).FirstOrDefault(b => b.Id == branchID);
return branchInfo.Name;
}
return string.Empty;
}

Related

Sitefinity get current dynamiccontent item from code

I'm currently writing a site using Sitefinity CMS. Can someone please explain how to get the current dynamic content item from server side code on page_load?
I have written a user control to display a custom gallery of sliding images. There are multiple content types in my dynamic module. The user control will sit as part of the masterpage template rather than on every page. On each page load I would like to fetch the current dynamiccontent item that is associated with the page and examine whether it has a property with the name 'Gallery'. If so I would then extract the images and render them via the usercontrol.
Thanks,
Brian.
I'm assuming your images are related content. This gets every published content item of your type.
var dynamicModuleManager = DynamicModuleManager.GetManager();
var moduleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.YOURTYPEHERE");
var dcItems = dynamicModuleManager.GetDataItems(moduleType)
.Where(l => l.Status == ContentLifecycleStatus.Master);
foreach (var dcItem in dcItems)
{
//pass the dynamic content item to a model constructor or populate here, then
// get your image this way:
var image = dcItem.GetRelatedItems<Image>("Images").SingleOrDefault();
if (image != null)
{
ImageUrl = image.MediaUrl;
}
}

Share data between scripts?

I want to create a scoring system. I have 4 buttons with 4 different but similar scripts and want to share 1 GUI Text for the scores. Example Code:
var something : Sprite;
var SpriteRenderer : SpriteRenderer;
var score : int = 0;
var guiScore : GUIText;
function OnMouseDown () {
if(SpriteRenderer.sprite == something) {
score += 1;
guiScore.text = "Score: " = score;
}
}
Right now, if I pressed a button and got a point then I pressed a different button the score would start from 0 again. How can I share data something like static variables but different scripts? I know this sounds a bit noobie but any help would be much appreciated. Thanks in advance
Static variables won't appear in the inspector so you can't assign the GUIText in the inspector (thanks for making me find out). So try using GetComponent instead:
// make a variable of type GUIText
var guiScore: GUIText;
// assign the gameobject in the inspector
var staticObject: GameObject;
// Again I don't know the name of your script, so I'll name it StaticScript
// get the script
StaticScript scr = staticObject.GetComponent(StaticScript);
// assign local GUIText with the one from above
guiScore = scr.guiScore;
This way you have already shared 1 GUIText for all other scripts.
However you said:
Right now, if I pressed a button and got a point then I pressed a
different button the score would start from 0 again
Doesn't that mean something is wrong with the score, not the GUIText?

Using extendscript (javascript) how can I get the color values from the Photoshop color table

I'm writing a Photoshop script in extendscript/javascript and I'm trying to verify that the document is using just one color (plus transparency). What I would like to do is change the document mode to Indexed Color and then get the values in the color table.
I have successfully changed the document mode to Indexed Color but can't figure out how to access the color table or the color values inside of it.
My working alternative is to use a colorSampler to compare the values of each pixel, but that can take a couple of minutes to run on larger documents and speed is an issue for this project.
Please let me know if there is a way to access the color table or if you see a way to reduce the time it takes to run this function.
function sample_color(doc, sample_rate) {
var status = 'PASS'
var color_sampler = doc.colorSamplers.add([0,0])
var color_val = false //first (and hopefully only) color value in the document
var broke = false
for (x=1; x < doc.width; x+=sample_rate){
if (broke){
break
}
for (y=1; y < doc.height; y+=sample_rate){
color_sampler.move([UnitValue(x, 'px'), UnitValue(y, 'px')])
try{
var color = color_sampler.color //color of the current pixel
} catch(e) {
var color = false //color_sampler.color fails if the pixel is transparent
}
if (color != false){
if (color_val != false){
if (!color.isEqual(color_val)){
status = 'FAIL'
broke = true
break
}
} else {
color_val = color
}
}
}
}
color_sampler.remove()
return status
}
xbytor has written a couple of scripts for accessing colour tables. This link may be of use to you.

Creating a closeable tab in Mono/GTK

I'm trying to create new GTK Notebook tabs that contain both a name (as a Label) and a close button (as a Button with an Image) with the following code:
Label headerLabel = new Label();
headerLabel.Text = "Header";
HBox headerBox = new HBox();
Button closeBtn = new Button();
Image closeImg = new Image(Stock.Close, IconSize.Menu);
closeBtn.Image = closeImg;
closeBtn.Relief = ReliefStyle.None;
headerBox.Add(headerLabel);
headerBox.Add(closeBtn);
headerBox.ShowAll();
MyNotebook.AppendPage(childWidget, headerBox);
This seems to work just fine; however, the button is about 1.5 - 2 times the size is needs to be, so there is a lot of extra space around the image inside the button. Having looked at remove inner border on gtk.Button I now see that the culprit is the "inner-border" style property of the GtkButton, but (being new to GTK) I can't seem to figure out how to override its value.
Is there some method of doing this that I'm missing? I don't have any reservations about not using a Button/Image combination, so any more obvious suggestions are welcome.
Note: I have seen the suggestion in the linked question to use an EventBox, but I was not able to add the Relief and mouseover effects to that Widget.
You are in luck. I just made the exact same thing yesterday, and can fortunately give you some code. The trick is to create a Custom Tab Widget.
public class MultiTab : Gtk.Box
{
public Gtk.Label Caption;
Gtk.Image img = new Gtk.Image(Platform.IMG + "tab_close.ico");
public Gtk.ToolButton Close;
public Gtk.Notebook _parent;
public MultiTab ( string name )
{
CreateUI(name);
}
public MultiTab(string name, Gtk.Notebook parent)
{
_parent = parent;
CreateUI(name);
CreateHandlers();
}
void CreateUI(string name)
{
Caption = new Gtk.Label(name);
Close = new Gtk.ToolButton(img,"");
PackStart( Caption );
PackStart( Close );
ShowAll();
Close.Hide();
}
void CreateHandlers()
{
Close.Clicked += delegate {
_parent.RemovePage(_parent.CurrentPage);
};
}
public bool Active;
}
Next all you have to do is use this widget(or a similar one created by you) in Gtk.Notebook like this:
MyNoteBook.AppendPage(new <YourPage>(), new MultiTab("<your caption>",this));
And You're done.
Here is a screenshot:
Add this:
RcStyle rcStyle = new RcStyle ();
rcStyle.Xthickness = 0;
rcStyle.Ythickness = 0;
closeBtn.ModifyStyle (rcStyle);
Add items to box using Gtk.Box.PackStart/PackEnd methods rather than generic Gtk.Container.Add method. PackStart/PackEnd will allow you control how child widgets will be allocated space:
headerBox.PackStart (headerLabel, true, true, 0);
headerBox.PackEnd (closeBtn, false, false, 0);

Eclipse RCP: Is it possible to shift the fields up without redrawing?

In my editor, I have a composite containing a label control right at the top which flashes informative message in red colour whenever the user enters erroneous inputs in any of the below lying fields. The text keeps changing dynamically depending on user's input. I am able to achieve the effect of displaying red coloured text on erroneous inputs and displaying nothing in the label for correct inputs.
But, I want that when there is no error to display in the label composite, the rest of the below fields shift up in display. And when there is error to display, the error should appear in it's place(at the top of all other fields) pushing the other fields down.
Is there a way to achieve this effect without redrawing all the controls again?
Yes, call layout (true) on the parent.
For example I have a view that has a search bar at the top who's visibility can be toggled. I have a method to create the search composite and one to remove it:
private void createNameSearchBar () {
mySearchControl = new CardSearchControl (myViewComposite, SWT.NONE);
mySearchControl.setSearchListener (this);
}
private void disposeNameSearchBar () {
mySearchControl.dispose ();
mySearchControl = null;
}
private CardSearchControl mySearchControl = null;
private Composite myViewComposite;
private boolean mySearchBarState;
To hide or show the search bar control I call this method (myViewComposite is the top level control that owns the search bar and all the other contorls):
public void setSearchBarState (boolean show) {
mySearchBarState = show;
if (myViewComposite == null || myViewComposite.isDisposed ())
return; // no work to do
if (mySearchBarState && mySearchControl == null) {
createNameSearchBar ();
mySearchControl.moveAbove (null);
myViewComposite.layout (true);
} else if (!mySearchBarState && mySearchControl != null) {
disposeNameSearchBar ();
myViewComposite.layout (true);
}
}