public async Task TestModifyRecordWithRelatedData() { var targetLayout = "cake_utility"; Login(); fms.SetLayout(targetLayout); // first create a record and capture the ids var request = fms.NewRecordRequest(); request.AddField("cake", RandomString(50, false)); request.AddField("wine_pairing", "first value"); request.AddField("country", RandomString(50, false)); request.AddRelatedField("fruit", "cake_FRUIT__ac", "related - first value"); var id = await request.Execute(); // get the data for the new record so that we can get the related id var find = fms.FindRequest(id); var reply = await find.Execute(); var relatedId = reply.data.foundSet.records[0].relatedRecordSets[0].records[0].recordId; var TOname = reply.data.relatedTableNames[0]; // now modify that record var editRequest = fms.EditRequest(id); editRequest.AddField("wine_pairing", "second value"); editRequest.ModifyRelatedField("fruit", TOname, "second value", Convert.ToInt32(relatedId)); var newModId = await editRequest.Execute(); Logout(); // the mod id returned from the edit should be 1 because it was a new record and this was the first edit Assert.True((newModId == 1 && id > 0 && Convert.ToInt32(relatedId) > 0)); }
//To add a new image against product/item private async Task CreateImage(string productRecordId, string fileName, object sender) { fmServer.SetLayout(productLayout); var newEditRequest = fmServer.EditRequest(Convert.ToInt32(productRecordId)); newEditRequest.AddRelatedField("PositionNumber", "products||SPECGRAPHICS", "1", "graphicsportal"); var editRequestResponse = await newEditRequest.Execute(); var errorCheck = fmServer.lastErrorCode; var productPortalAndRecordId = await GetProductGraphicsPortalAndRecordID(Convert.ToInt32(productRecordId)); var productPortalData = productPortalAndRecordId.GraphicsPortalData; var latestPortalRecordId = 0; if (productPortalData != null) { var portalDataRecordCount = productPortalData.records.Count(); latestPortalRecordId = Convert.ToInt32(productPortalData.records.ElementAt(portalDataRecordCount - 1).recordId); } fmServer.SetLayout(graphicLayout); var graphicsRequest = fmServer.NewRecordRequest(); graphicsRequest.AddField("GraphicURL", ""); var newGraphicRecordId = await graphicsRequest.Execute(); if (fmServer.lastErrorCode != 0) { MessageBox.Show($"Error: {fmServer.lastErrorMessage}"); } FileInfo fileInfo = new FileInfo(fileName); fmServer.SetLayout(graphicLayout); int uploadContainerResponse = await fmServer.UploadFileIntoContainerField(newGraphicRecordId, "File", fileInfo); if (fmServer.lastErrorCode != 0) { MessageBox.Show(fmServer.lastErrorCode.ToString() + " - " + fmServer.lastErrorMessage); } var findGraphicRequest = fmServer.FindRequest(newGraphicRecordId); var findGraphicResponse = await findGraphicRequest.Execute(); var graphicFile = findGraphicResponse.data.foundSet.records.First().fieldsAndData["File"]; fmServer.SetLayout(productLayout); newEditRequest = fmServer.EditRequest(Convert.ToInt32(productRecordId)); newEditRequest.ModifyRelatedField("File", "products||SPECGRAPHICS||GRAPHICS", graphicFile, latestPortalRecordId, "graphicsportal"); editRequestResponse = await newEditRequest.Execute(); fmServer.SetLayout(graphicLayout); uploadContainerResponse = await fmServer.UploadFileIntoContainerField(newGraphicRecordId + 1, "File", fileInfo); errorCheck = fmServer.lastErrorCode; var base64String = string.Empty; using (Image image = Image.FromFile(fileName)) { using (MemoryStream m = new MemoryStream()) { image.Save(m, image.RawFormat); byte[] imageBytes = m.ToArray(); base64String = Convert.ToBase64String(imageBytes); } } var button = sender as Button; button.BackgroundImage = Convertbase64ToImage(base64String); button.BackgroundImageLayout = ImageLayout.Stretch; button.Tag = $"{newGraphicRecordId + 1}, {productRecordId}"; }