Get Uid project by name

Jan 14, 2012 at 5:59 AM

Hi,

I'm looking for method to get project uid by name.

i know that is possible from sql.

is it possible from fluentps?.

Thank's.

Coordinator
Jan 14, 2012 at 9:18 AM

Hi,

Sure, this is possible with FluentPS.

Please try the following code snippet:

using System;
using System.Linq;
using FluentPS.Services.Impl;
using FluentPS.WebSvcCustomFields;
using FluentPS.WebSvcLookupTable;
using FluentPS.WebSvcProject;
using FluentPS.WebSvcView;
using FluentSP.Services.Impl;
//...

// Your Project Name
string projectName = "project_name";
            
var logService = new LogService();
var sessionService = new PSSessionService()
{
    HostName = "your_host_name", // your PWA host name
    SiteName = "your_site_name", // your PWA site name
};

PsiContextService psiContextService = new PsiContextService();
PSISvcsFactory psiSvcsFactory = new PSISvcsFactory(sessionService, psiContextService);

LookupTable svcLookupTable = psiSvcsFactory.CreateSvcClient<LookupTable>();
CustomFields svcCustomFields = psiSvcsFactory.CreateSvcClient<CustomFields>();
View svcView = psiSvcsFactory.CreateSvcClient<View>();
Project svcProject = psiSvcsFactory.CreateSvcClient<Project>();

EnvironmentService environmentService = new EnvironmentService();
PSLookupTableService lookupTableService = new PSLookupTableService(logService, svcLookupTable);
PSCustomFieldService customFieldService = new PSCustomFieldService(logService, svcCustomFields, svcView, environmentService, lookupTableService);
PSProjectService<ProjectEntity> projectService = new PSProjectService<ProjectEntity>(logService, lookupTableService, customFieldService, svcProject);

// Getting Project Uid
Guid projectUid = projectService.GetAll(FluentPS.Enums.ProjectData.BasicInfo)
    .Where(project => project.Name == projectName)
    .Select(project => project.Uid)
    .FirstOrDefault();
            

// Project Entity class 
[FluentPS.Attributes.PSEntityType(FluentPS.Enums.PSEntityType.Project)]
public class ProjectEntity
{
    [FluentPS.Attributes.PSEntityUidField(ColumnName = FluentPS.Consts.ProjectCustomFieldsColumnNames.PROJ_UID)]
    public Guid Uid { get; set; }

    [FluentPS.Attributes.PSEntityUidField(ColumnName = FluentPS.Consts.ProjectCustomFieldsColumnNames.PROJ_NAME)]
    public string Name { get; set; }
}

Regards,

Viacheslav

Jan 16, 2012 at 3:39 PM
hp9000 wrote:

Hi,

I'm looking for method to get project uid by name.

i know that is possible from sql.

is it possible from fluentps?.

Thank's.


Hi,

It works with FluentPS as Viacheslav describes. However you you should have in mind that the FluentPS code first gets all projects and then iterates through these to get the one Guid you need.

From my point of view and if you already have code that does this in Sql (should be Draft DB) I would recommend you keep using that as it will be much faster.