Quantcast
Channel: CRM Development 論壇
Viewing all articles
Browse latest Browse all 10280

Update User record using a C# application.....

$
0
0

Hi Everyone.

I am using a LINQ query to retrieve the count of users that has a custom Boolean field set to true.

Here it is:

  public static int GetItsmUser(IOrganizationService service)
        {
            OrganizationServiceContext context = new OrganizationServiceContext(service);
            IEnumerable<Entity> user = (from usr in context.CreateQuery("systemuser")
                        where (bool)usr["apitil_isitsmserviceuser"] == true
                        select usr);
            var count = user.Count();
            return count;
        }

This works fine.

However, I am calling this method and I am trying to set the Initiating user's custom boolean field to true.

 private void button2_Click(object sender, EventArgs e)
        {

            IOrganizationService service = TargetConnection.GetOrganizationService();
         
            if (GetItsmUser(service) == 0)
            {
                Entity entity = new Entity("systemuser");
                entity["apitil_isitsmserviceuser"]= true;            service.Update(entity);
            }
                var fileprocessor = new DataFileProcessor();
                MessageBox.Show("Import of Sample Data has just started");
                fileprocessor.ProcessFiles(tbExportFolder.Text + "SampleData", service);
                MessageBox.Show("Import of Sample Data Complete");
        }
Pretty sure I am doing this incorrectly. Is there a way to do this without a plugin? I am creating an app that connects to the CRM online environment and I want to change the boolean field value of the initiating user based on a button press.




Viewing all articles
Browse latest Browse all 10280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>