How do I change State and/or Status of an entity in CRM 2013 using C#?
Neither CRM 2011's SetStateRequest nor the earlier SetStateDynamicEntityRequest are being recognized.
Searching online didn't seem to help either... Am I missing a namespace or something?
Thanks in advance
Namespaces:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Messages;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Web.Services.Protocols;
The function:
private void changeUserStatus(Guid userId, IOrganizationService service, int state)
{
SetStateRequest setStateRequest = new SetStateRequest
{
EntityMoniker = new EntityReference("systemuser", userId),
State = new OptionSetValue(state),
Status = new OptionSetValue(-1),
};
service.Execute(setStateRequest);
}
IMPORTANT: My SetStateRequest is NOT recognized by visual studio 2012, so unlike the above example it's not highlighted and actually red underlined with the "the type or namespace not found" message displayed when hovering
Edit: I see the question got downvoted and I'm sorry if I'm missing something but I really have no more information to provide apart from the fact that I've spent 4 hours yesterday looking for this online (including stackoverflow) without any avail. I may be using the wrong search criteria or looking in the wrong places, but if that's the case could anyone at least point me in the right direction? I'm a beginner on all of this (both stackoverflow and crm2013) and I'm kind of stuck on this. Thanks again
You are not referencing microsoft.crm.sdk.proxy.dll and its namespace Microsoft.Crm.Sdk.Messages
so the code will be
using Microsoft.Crm.Sdk.Messages;
Another thing, be sure that the int values for State and Status are valid for the entity (in your case systemuser)
Related
I'm following a guide to write output data from Visual Studio into a google spreadsheet. I'm using a NUnit project type for test-automation purposes.
At the end of the guide there is a code block that I pasted inside my project:
using OpenQA.Selenium.Support.UI;
using System;
using NUnit.Framework;
using OpenQA.Selenium;
using System.Collections;
using System.Collections.Generic;
using Google.Apis.Sheets.v4;
using Google.Apis.Auth.OAuth2;
using System.IO;
using Google.Apis.Services;
using Newtonsoft.Json;
using WikipediaTests.Foundation_Class;
namespace AutomationProjects
{
[TestFixture]
public class TestClass : TestFoundation
{
public class SpreadSheetConnector
{
//Codeblock from guide pasted here!
}
[Test]
public void test1()
{
//Test case 1. Do XYZ...
}
}
}
In the code block included in the guide there is a section that reads the JSON credential file:
private void ConnectToGoogle()
{
GoogleCredential credential;
using (var stream = new FileStream(Path.Combine(HttpRuntime.BinDirectory, "Export Project-03e8aa07234e.json"),
FileMode.Open, FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream).CreateScoped(_scopes);
}
//...
But I get an error for the 'HttpRuntime' saying: Error CS0103 The name 'HttpRuntime' does not exist in the current context
There is no suggestion from VS to add a new 'using' reference so I'm assuming that is not the problem.
So what could be the problem? To whole codeblock from the: guide
Short answer - yes.
Long answer - I believe you need to add the System.Web dll here. C# projects do not add all dependencies by default -- rather, they provide you with a list of potential references, and let the user pick and choose on an as-needed basis.
Under your project, find the Dependencies section. Right click, and click Add Reference. Under Assemblies, find System.Web and check the box next to it, then click OK.
Once you add that, then you will need to add using System.Web to the top of your file.
This guide may help too: https://learn.microsoft.com/en-us/visualstudio/ide/how-to-add-or-remove-references-by-using-the-reference-manager?view=vs-2019
I was wondering if any wonderful person with experience of using nHAPI in C# would be able to help a newbie out with the OBR-15 field (Specimen Source) of an HL7 message? I've dug around and I can't find any documentation online to help me out, so I'd be grateful for any suggestions.
My problem is, I can't find the correct method for filling the OBR-15 field using nHAPI. I'm hoping to send an OBR segment that looks like this (I've removed data from all other fields except OBR15, so my actually message isn't as bare as this):
OBR|1||||||||||||||T034^Blood||||||||||||||||||||
I've tried every way possible to form this field with no success. I'm always getting an ampersand that appears in the front everything I'm sending, which means that the field is unreadable in downstream applications:
OBR|1||||||||||||||&T034^^^^^^&Blood||||||||||||||||||||
My OBR-15 code snippet (I've just kept the relevant stuff in here, as otherwise this section would be massive):
using System;
using System.Collections.Generic;
using System.Web.Services;
using NHapi.Model.V24.Message;
using NHapi.Model.V24.Segment;
using NHapi.Model.V24.Group;
using System.Data;
using System.Text;
using NHapi.Base.Parser;
using NHapi.Model.V24.Datatype;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Data.SqlClient;
namespace HL7WebService
{
public class HL7Reporting : System.Web.Services.WebService
{
private ORU_R01 Create_ORU_R01(Dictionary <string,string> reportData, int reportNumber)
{
ORU_R01 oruR01 = new ORU_R01();
// lots of stuff removed for clarity
ORU_R01_ORDER_OBSERVATION oruR01OrderObs = oruR01.GetPATIENT_RESULT().GetORDER_OBSERVATION(1);
OBR obr = oruR01OrderObs.OBR;
// OBR-15 Specimen Source
obr.SpecimenSource.SpecimenSourceNameOrCode.Text.Value = "T034";
obr.SpecimenSource.SpecimenRole.Text.Value = "Blood";
// lots of other stuff removed for clarity
return oruR01;
}
}
}
I'm using nHapi (v2.5.0.6) and visual studio 2015. If I've missed anything out or you require any further information, just let me know and I'll provide it. Thanks!
I solved it by declaring OBR-15 the following way:
obr.SpecimenSource.SpecimenSourceNameOrCode.Identifier.Value = "T034";
obr.SpecimenSource.Additives.Value = "Blood";
I'm facing a very strange error in my VS2010 project that uses c# + OpenTK + Assimp.net (The packages of the last 2 are from NuGet, so I suppose them updated to their latest version)
When I try to iterate the vector3 of the UV coordinates using:
model.Meshes[n].GetTextureCoords(0)[i]
I get the following error:
error CS1061: 'Assimp.Mesh' does not contain a definition for
'GetTextureCoords' and no extension method 'GetTextureCoords'
accepting a first argument of type 'Assimp.Mesh' could be found (are
you missing a using directive or an assembly reference?)
I don't understand why! Can someone please help me?
AssimpNet is correctly referenced (I'm able to load and visualize any 3D model correctly if I comment the UV part)
And in the using part:
using System;
using System.Collections.Generic;
using System.IO; //Required by Assimp-net
using System.Reflection; //Required by Assimp-net
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Platform;
using Assimp; //Required by Assimp-net
using Assimp.Configs; //Required by Assimp-net
EDIT: I also tried to change the order of the "using"s... or to remove some of them to see if there was some sort of namespace clashing but without any success
It's simply Mesh.TextureCoordinateChannels[0][i]. GetTextureCoords() does not exist. If you saw it anywhere in a tutorial, let me know where.
I can't seem to resolve the following error that states:
"System.Linq.IQueryable' does not contain a definition for
'ToGridModel' and no extension method 'ToGridModel' accepting a first argument of type
'System.Linq.IQueryable'could be found (are you missing a using directive or an assembly reference?)"
Any ideas about how I can resolve this issue?
Am I missing a "using" statement at the top of my file somewhere, or do I need to modify
ToGridModel to some other kind of command?
I'm using Telerik UI for ASP.NET Mvc, Kendo UI,
and Telerik Data Access extensions by the way.
I'm also receiving similar errors for the Viewbag as well in my Controller files.
I'm not too sure how to fix that major issue either.
Any help would be greatly appreciated. Thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.IO;
using System.Text;
using System.Collections;
using Kendo.Mvc;
using KendoGridBinder;
using NPOI.HSSF.UserModel;
namespace AssetMgr_TeleMVC.Controllers
{
public class SharedController : Controller
{
// GET: Shared
// Exports the whole selected grid to csv in comma separated format
public ActionResult ExportCsv(int page, string orderBy, string filter)
{
// IEnumerable orders = GetOrders().AsQueryable().ToGridModel(page, 10, orderBy, string.Empty, filter).Data;
using (Model_OpenAccess_AssetMgr.ctx_OpenAccess_AssetMgr dbContext = new Model_OpenAccess_AssetMgr.ctx_OpenAccess_AssetMgr())
{ IEnumerable TableRows = dbContext.Assets.AsQueryable().ToGridModel(page, 10, orderBy, string.Empty, filter).Data;
MemoryStream output = new MemoryStream();
StreamWriter writer = new StreamWriter(output, Encoding.UTF8);
writer.Write("HSC TAG,");
writer.Write("Asset Name,");
The equivalent method in UI for ASP.NET MVC is ToDataSourceResult. You need to import the Kendo.Mvc.Extensions namespace.
Just add Telerik.Web.Mvc.Extensions to your 'using' section. that's all
I am trying to convert some vb.net to C#, but I keep getting errors. At the moment, I am getting the following error:
The name 'Strings' does not exist in the current context
The problem line is:
strUser = Strings.LCase(Strings.Trim(strUserInitials[strUserInitials.GetUpperBound(0)])).ToString();
Anyone know why this is happening?
I have the following namespaces set:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Script;
using System.Web.Script.Services;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
I am working on a webservice (asmx file).
The Strings utility class is in the Microsoft.VisualBasic namespace.
You can add a reference to the library and use it from your C# code, or rewrite the calls:
strUser = strUserInitials[strUserInitials.GetUpperBound(0)].ToString().Trim().ToLower();
In c# there is no Strings class in System namespace. and in the string change LCase to ToLower, So:
strUser = string.ToLower(string.Trim(strUserInitials[strUserInitials.GetUpperBound(0)]));