Are webresources once published always published? - dynamics-crm-2011

Consider the following plugin...infrastructure build up omitted for brevity.
protected override void Execute()
{
//Not all Targets are of entity so let's check first
if (Context.InputParameters.Contains("Target") && Context.InputParameters["Target"] is Entity)
{
if (Message == EMessage.Create)
{
throw new InvalidPluginExecutionException("InCreate");
}
else if (Message == EMessage.Update)
{
//I don't think this is right way to do this.
if (PreEntityImage.GetAttributeValue<OptionSetValue>("componentstate").Value == new OptionSetValue(0).Value)
{
throw new InvalidPluginExecutionException("UpdatePublishedMessage");
}
else
{
throw new InvalidPluginExecutionException("UpdateMessageOnly");
}
}
}
}
This plugin is registered for the Create & Update message on webresource.
So when the webresource is created my plugin fires and branches into the Create message section.
When the webresource is updated I branch into the Update section AND flow right into componentstate == published section!!??
I would have thought any change would have been flagged unpublished until I selected publish or publishall?
Some other details that may be relevant:
The webresource I am working with is a js file. Perhaps this is not the behavior for other webresource types like png?
The steps I am taking in updating the webresource are:
Open Test Solution
Open webresource js file
Open with text editor
Make Edits
Click OK---and plugin fires.
Thoughts, tips, edjumakation etc. greatly appreciated
Thank You

When saved and not published, Crm creates another record in webresources table. So for unpublished resources you have two entries: one record with componentstate = 0 and one with componentstate= 1.
I guess plugin works on the one that have 0 value. You might try query table to check if there's any with value 1 to determine if it's published or not. Or check any there paras passed to plugin.

Related

Adaptive Card QuickView Navigation not firing

Ok, so I'm just getting started with adaptive cards and downloaded the PNP ACE project (Git Hub Link) to use as a jumping off point. Started the project up and ran gulp serve.... everything seemed great.... until I tried to click either the View Items or Add Item buttons on the CardView. Both of these buttons fire QuickViews, but when you click them nothing happened. Tried 2 different browsers, no errors registered in the console, it just acts like there isn't an action tied to the buttons.
So, thinking "well maybe something got screwed up in a commit", I started a brand new project using yeoman.
Got the project set up, building and served it up; EXACT SAME PROBLEM!! The button in the default ACE project template didn't work either. I can't figure out what gives.
Here is the function for the button that the template created :
public get cardButtons(): [ICardButton] | [ICardButton, ICardButton] | undefined {
return [
{
title: strings.QuickViewButton,
action: {
type: 'QuickView',
parameters: {
view: QUICK_VIEW_REGISTRY_ID
}
}
}
]};
That looks just like the PNP example (and every other example I've seen online). Even the quickViewNavigator is populated the same. Here is the one from the template project (class definitions removed to save space):
const CARD_VIEW_REGISTRY_ID: string = 'JasonAdaptiveTest_CARD_VIEW';
export const QUICK_VIEW_REGISTRY_ID: string = 'JasonAdaptiveTest_QUICK_VIEW';
public onInit(): Promise<void> {
this.state = { };
this.cardNavigator.register(CARD_VIEW_REGISTRY_ID, () => new CardView());
this.quickViewNavigator.register(QUICK_VIEW_REGISTRY_ID, () => new QuickView());
return Promise.resolve();
}
So what gives? Why do these not work? Is there some NPM package that may be missing?
Well, found the line buried in the tutorials that explains my problem. A single note, in a page that isn't necessarily about quick views.
Note
ACE interaction is disabled while in Edit mode. The Workbench or Page must be >in Preview or Read mode to interact with the ACE.

How can I automate the creation and SFTP transfer of a snapshot in Acumatica?

I would like to create a nightly snapshot of certain tables in my SAAS-hosted Acumatica instance and SFTP the resulting XML file to a given location. (I've created a custom Export Mode option for just the tables of interest.)
I would like to do this process through an Acumatica Automation Schedule, a custom Action that I can call through the API, or an API call to existing Acumatica Actions, or some combination of the above.
However, it doesn't appear that these options are available to me:
Automation Scheduling doesn't support snapshot creation (https://feedback.acumatica.com/ideas/ACU-I-570)
I tried adding the Action to create a snapshot to the web service endpoint, but it doesn't appear that I can pass the parameters I would need to manage the pop-ups
Attempting to create a custom Acumatica button, I'm also to struggling to figure out how to raise and manage the pop-ups.
Once I have the snapshot created, I presume I will need to be able to download it locally in order to SFTP it to my desired location; I haven't gotten far enough to know if I invoke the download snapshot button through the API where the resulting file will go.
June,
When I get stuck with stuff that I am unable to trigger with ReST or other integration techniques I generally turn to Selenium as the path of least resistance. I do want to point out I always err on the side of using selenium as a last resort.
I generally like to use the PowerShell selenium module for stuff like this.
Once you have your script working you can wire it into a standard Windows Scheduler real easy.
It may not be the most elegant way to do it but it will certainly get the job done.
if your interested you can get started with this
https://github.com/adamdriscoll/selenium-powershell/blob/master/README.md
Once you get familiar with it you use the chrome inspection tool to dig into the elements that you need to target. the dialog boxes you are after are often found as iframes within the page.
I can share some of my scripts to help you get started if you want to try this route.
I hope this helps.
Robert
I ended up creating a simple console application since it was more in line with our other applications and I have more familiarity with C# than with PowerShell. Robert, your project was invaluable to figuring out how to reference the trickier elements.
I expect to set up scheduled tasks that will call my application with the method name of each step, with appropriate delays between each -- creating the snapshot takes about 25 minutes, for example. There are separate methods to create the snapshot, download the snapshot, delete the snapshot, and next I'm working on SFTPing the downloaded snapshot to its end destination. I put in sleeps to allow time for the website to catch up; there are Waits and WaitForExpectedCondition methods available but I didn't get into them in this quick and dirty version.
Here's the guts of my code. (I added WebDriver and ChromeDriver to the application via Nuget.)
using System;
using System.Collections.Generic;
using System.Linq;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Threading;
namespace InfiniteExport
{
class Program
{
static string connectorInfo;
static void Main(string[] args)
{
string method = "";
if (args.Count() >= 1)
{
method = args[0].ToLower();
}
IWebDriver driver = new ChromeDriver();
try
{
switch (method)
{
case "createsnapshot":
Login(driver);
CreateSnapshot(driver);
break;
case "downloadsnapshot":
Login(driver);
DownloadSnapshot(driver);
break;
case "deletesnapshot":
Login(driver);
DeleteSnapshot(driver);
break;
default:
break;
}
}
catch (Exception e)
{
throw e;
}
finally
{
driver.Quit();
}
}
static void Login(IWebDriver driver)
{
//This login actually results in a 404 error because there's no redirect embedded in it, but the login itself is successful and creates the session used by the next method navigation
driver.Navigate().GoToUrl(InfiniteExport.Properties.Settings.Default.BaseAcumaticaURL + "/Frames/Login.aspx");
driver.FindElement(By.Id("form1")).Click();
driver.FindElement(By.Id("txtUser")).SendKeys(InfiniteExport.Properties.Settings.Default.AcumaticaUserName);
driver.FindElement(By.Id("txtPass")).SendKeys(InfiniteExport.Properties.Settings.Default.AcumaticaPassword);
driver.FindElement(By.Id("btnLogin")).Click();
driver.Manage().Window.Maximize();
Thread.Sleep(5000);
}
static void CreateSnapshot(IWebDriver driver)
{
driver.Navigate().GoToUrl(#InfiniteExport.Properties.Settings.Default.BaseAcumaticaURL + "/Main?ScreenId=SM203520&_CompanyID=2");
Thread.Sleep(2000);
driver.SwitchTo().Frame("main");
//Click the #$##%*! unnamed create snapshot button
driver.FindElement(By.CssSelector(".toolsBtn[data-cmd=exportSnapshotCommand]")).Click();
Thread.Sleep(2000);
//Switch to the modal popup to start clicking items on it (this is the "Warning not in maintenance mode" popup)
driver.SwitchTo().ActiveElement();
driver.FindElement(By.Id("messageBox_0")).Click();
Thread.Sleep(2000);
//Switch to the modal popup with the export options
driver.SwitchTo().ActiveElement();
driver.FindElement(By.Id("ctl00_phF_pnlExportSnapshot_frmExportSnapshot_edDescription")).SendKeys("InfiniteExport");
//Select the dropdown option for the InfiniteExport
driver.FindElement(By.Id("ctl00_phF_pnlExportSnapshot_frmExportSnapshot_edExportMode_text")).Click();
driver.FindElement(By.Id("ctl00_phF_pnlExportSnapshot_frmExportSnapshot_edExportMode_text")).SendKeys("InfiniteExport");
Thread.Sleep(2000);
driver.FindElement(By.ClassName("ddSelection")).Click();
driver.FindElement(By.Id("ctl00_phF_pnlExportSnapshot_frmExportSnapshot_chkPrepare")).Click();
//Select the dropdown option for XML
driver.FindElement(By.Id("ctl00_phF_pnlExportSnapshot_frmExportSnapshot_edPrepareMode")).Click();
driver.FindElement(By.Id("ctl00_phF_pnlExportSnapshot_frmExportSnapshot_edPrepareMode_text")).SendKeys("XML");
Thread.Sleep(2000);
driver.FindElement(By.ClassName("ddSelection")).Click();
Thread.Sleep(2000);
//Click the OK button to start the export
driver.FindElement(By.Id("ctl00_phF_pnlExportSnapshot_btnExportSnapshotOK")).Click();
//Wait long enough for the process to start, then quit and come back later to download
Thread.Sleep(10000);
}
static void DownloadSnapshot(IWebDriver driver)
{
driver.Navigate().GoToUrl(#InfiniteExport.Properties.Settings.Default.BaseAcumaticaURL + "/Main?ScreenId=SM203520&_CompanyID=2");
Thread.Sleep(2000);
driver.SwitchTo().Frame("main");
//Unless this is made fancier, it will download the active grid row, which is the most recent snapshot created
driver.FindElement(By.CssSelector(".toolsBtn[data-cmd=downloadSnapshotCommand]")).Click();
Thread.Sleep(10000);
}
static void DeleteSnapshot(IWebDriver driver)
{
driver.Navigate().GoToUrl(#InfiniteExport.Properties.Settings.Default.BaseAcumaticaURL + "/Main?ScreenId=SM203520&_CompanyID=2");
Thread.Sleep(2000);
driver.SwitchTo().Frame("main");
//Unless this is made fancier, it will delete the active grid row, which is the most recent snapshot created
driver.FindElement(By.CssSelector(".toolsBtn[data-cmd=Delete]")).Click();
Thread.Sleep(2000);
driver.FindElement(By.CssSelector(".toolsBtn[data-cmd=saveCompanyCommand]")).Click();
Thread.Sleep(10000);
}
}
}

How can I change Magento theme via query string?

Is it possible to change Magento template via query string?
I am developing a custom template and sometimes I want to check if I broke something, so I want to change via query string the theme for the default one.
I am looing for something like this:
?_theme=default
Does something like this exists?
Programmatically:
You could write an observer that is listening to event <controller_action_predispatch>
The observer method could look like this:
public function changeTheme(){
if (Mage::app()->getRequest()->getParam('layout_switch') == '1'){
Mage::getDesign()->setArea(‘frontend’)
->setPackageName(Mage::app()->getRequest()->getParam('package'))
->setTheme(Mage::app()->getRequest()->getParam('theme'));
}
return;
}
}
Then you would just need to call your page with e.g.
yourdomain.com/index.php/layout_switch/1/package/default/theme/default
The short answer is no you can't (as far as I know)
However if it's your local installation (which you use only as a development enviroment!) you can use a trick:
Create another Store view and assign whatever theme you want to that store view and then access it like yourstore.com/?___store=storecode
as simple as 1-2-3.:) Create a new dev theme and copy all the files from the current live theme to the new one (both app/design and sking). Then observe controller_action_predispatch event and then in the observer function simply:
$controllerAction = $observer->getControllerAction();
if ($controllerAction->getLayout()->getArea() == Mage_Core_Model_App_Area::AREA_FRONTEND) {
$ipAddress = Mage::helper('core/http')->getRemoteAddr();
$ipAddresses = array('xxx.xxx.xxx.xxx');
if (in_array($ipAddress, $ipAddresses)) {
Mage::getDesign()->setTheme('theme-wanted');
}
}
Very helpful for design tweaks indeed. After the work is finished the observer should be disabled or module deactivated until next time

Overriding EmailRecieved without loosing the Base EmailRecieved functionality

I have a document library setup to recieve emails. The emails coming in have a single picture and a csv file which I use for some processing.
The override emailrecieved works perfectly but of course as I override I lose the nice SharePoint functionaliy that saves the incomming email as configured in the settings.
It was my understanding that I could call MyBase.EmailRecieved in my event for the underlying functionality to still work. This however is not working and no record of the email coming in is getting retained.
For now I am explicitly creating an audit trail but I would like to rely on SharePoints existing functionality as I believe it will be more robust.
What am I doing wrong with the MyBase.EmailRecieved call? Or what can I do instead if this doesnt work?
Thanks in advance.
When writing your own EmailReceived event receiver you will loose the default functionality.
What you will have to do is to implement this default functionality yourself. Let me give you a simple example. The following example saves all mail attachments to the list if they are *.csv files. You can do the same with the emailMessage and save it to the list as well. As you can see it is as easy as to add Files.Add to add a file to a document library.
public override void EmailReceived(SPList list, SPEmailMessage emailMessage, string receiverData)
{
SPFolder folder = list.RootFolder;
//save attachments to list
foreach (SPEmailAttachment attachment in emailMessage.Attachments)
{
if (attachment.FileName.EndsWith(".csv"))
{
var attachmentFileName = attachment.FileName;
folder.Files.Add(folder.Url + "/" + attachmentFileName, attachment.ContentStream, true);
}
}
list.Update();
}

Upload document to specific folder in a SharePoint Document library using WebClient

I have some client side code that uploads an Outlook email to a document library and as long as the path is pointing to the root of the doc library it works just fine.
#"https://<server>/sites/<subweb>/<customer>/<teamweb>/<Documents>/" + docname;
is the projectUrl in this function :
public bool SaveMail(string filepath, string projectUrl)
{
try
{
using (WebClient webclient = new WebClient())
{
webclient.UseDefaultCredentials = true;
webclient.UploadFile(projectUrl, "PUT", filepath);
}
}
catch(Exception ex)
{
//TO DO Write the exception to the log file
return false;
}
return true;
}
but I have not been able to figur out how to upload to an existing folder i.e. "Emails" in the same document library.
Not even Google seems to know the answer :-)
Note: I know that I could use something like the Copy web service within SharePoint to move the file to its final destination, but that is more like a workaround.
When will I learn not to work that late into the night :-(
Sorry about that question. Igalse is right, I just needed to add "emails/" to the URL. I could swear that I had tried that, but then again it sure looks like I didn't.
With your code I just added /Emails/ to the projectUrl and the upload worked just fine. Have you tried that? Maybe you have permission problem.

Resources